expr-eval icon indicating copy to clipboard operation
expr-eval copied to clipboard

Access object properties using brackets

Open coco-super opened this issue 3 years ago • 2 comments

Use the latest version and write the following code: Parser.evaluate('in1["key"]', { in1: { key: 'value' } });

I expect the above code to output "value", but got undefined

Can you spare some time to have a look? Thank you. @silentmatt

coco-super avatar Dec 01 '21 06:12 coco-super

I try to find answers in other issues. Find similar problems, but this is not what I want. #114

coco-super avatar Dec 01 '21 06:12 coco-super

https://github.com/silentmatt/expr-eval/blob/6e889e0e75c50ac37d70c35388602025650e0c50/src/functions.js#L253 The above code is modified as:

export function arrayIndex(array, index) {
  if (Array.isArray(array)) {
    return array[index | 0];
  }
  return array[index];
}

Then the world will be peaceful.

coco-super avatar Dec 02 '21 06:12 coco-super