diff --git a/src/jsonata.js b/src/jsonata.js index 58077366..c21eb1e2 100644 --- a/src/jsonata.js +++ b/src/jsonata.js @@ -397,7 +397,7 @@ var jsonata = (function() { // count in from end of array index = input.length + index; } - var item = input[index]; + var item = await input[index]; if(typeof item !== 'undefined') { if(Array.isArray(item)) { results = item; diff --git a/test/async-function.js b/test/async-function.js index 60de7561..a537987f 100644 --- a/test/async-function.js +++ b/test/async-function.js @@ -176,3 +176,13 @@ describe('Handle chained functions that end in promises', function() { }); }); + +describe('Array with Promise items', function() { + it('should await each item', async function() { + var data = { + list: [Promise.resolve({name: 'hello'})] + }; + var expr = jsonata('list[0].name'); + return expect(expr.evaluate(data)).to.eventually.equal('hello'); + }); +}); \ No newline at end of file