Uh oh!
There was an error while loading. Please reload this page.
Use Array.isArray to check if query is an array - #154
Conversation
arnaudlewis
commented
May 4, 2017
Hi @edance, what's your version of node and how did you have your error? Any call to the query function throw an error because of this? |
edance
commented
May 4, 2017
Hi @arnaudlewis, I am using node v6.10.0 and prismic 3.5.6. My code looks like this: constquery=[Prismic.Predicates.at('document.type',documentType),Prismic.Predicates.fulltext('document',params.q||''),];returnPrismic.api(URL).then((api)=>{returnapi.query(query,{page: params.page||1,pageSize: params.pageSize||20,orderings: `[my.${documentType}.date desc]`,});});In this check:
I pass everything except for the last conditional. For me:
But switching to |
edance
commented
May 4, 2017
Also another thought... Technically we need to check if all the objects in the array are arrays, not just the first one. We could do something like this to check that the object is an array of arrays.
|
Running this in node, I was hitting an error. I was getting typeof
Objectinstead of array.This fix is only supported in IE 9 and above (not sure if you all are supporting IE 8).
If IE 8 is required, we can switch this to:
Object.prototype.toString.call(query) == '[object Array]'