I have JSON data that I am searching through using filter
:
myJsonData.filter(function (entry) { return (entry.type === 'model' || entry.type === 'photographer' ); });
Now instead of specifying those conditions after return, I've created a similar string (because I want to have a list of pre-created search conditions) then using eval()
so:
myJsonData.filter(function () { return eval(stringToSearch) ; });
This appears to work. However, I just want to confirm, is this its correct usage? Are there any risks/issues in doing this?
I want to have the flexibility to do, any kind of search e.g.:
myJsonData.filter(function (entry) {
return (entry.type === 'model' || entry.type === 'photographer')
&& entry.level.indexOf('advanced') > -1 ;
});
That's why I made a separate class to create that string.