JSFiddle - React, Tailwind, and code Playground
by sperske
JavaScript
var data = {
"reasons": {
"options": [{
"value": "",
"label": "Seleziona una voce",
"selected": true,
"requiresValidation": false
}, {
"value": "small",
"label": "Too little",
"selected": false,
"requiresValidation": false
}, {
"value": "big",
"label": "Too big",
"selected": false,
"requiresValidation": false
}, {
"value": "unsuitable",
"label": "I don't like it",
"selected": false,
"requiresValidation": true
}, {
"value": "other",
"label": "Other",
"selected": false,
"requiresValidation": true
}]
}
},
extractWhere = function (is, source) {
var output = [],
index,
element;
for (index = 0; index < source.reasons.options.length; index++) {
element = source.reasons.options[index];
if (is(element)) {
output.push(element);
}
}
return output;
};
console.log(extractWhere(function (thing) {
return thing.value === 'other' && thing.requiresValidation;
}, data));