Сообщение от рони
|
<script>
var people = [
{ "name": "bob", "dinner": "pizza" },
{ "name": "john", "dinner": "sushi" },
{ "name": "john", "dinner": "hummus" }
];
var str = "sushi";
var obj = people.filter(function (person) { return Object.values(person).some(function(val) {
return val.toUpperCase() == str.toUpperCase()
})});
document.write(JSON.stringify(obj, null, 4))
</script>
|
Uncaught TypeError: val.toUpperCase is not a function - если в объекте есть еще массив.
var people = [
{ "name": "bob", "dinner": [ "sushi", "pizza" ] },
{ "name": "john", "dinner": "sushi" },
{ "name": "john", "dinner": "hummus" }
];