JSON find all Objects
You are Here:
JSON find all Object
In the following example, we will find all the occurrence of objects in an array with the age property less than 30.
Example
HTML Editor
<!DOCTYPE html>
<html lang="en-US">
<body>
<h1>JSON find all</h1>
<p>Find all while age is lesser than 30</p>
<button onclick="myFunction()">Click Me</button>
<script>
var data = [
{
"name": "Danny",
"age": 25,
"color": ["blue", "red", "green"]
},
{
"name": "Mike",
"age": 35,
"color": ["black", "red", "purple"]
},
{
"name": "Jade",
"age": 18,
"color": ["yellow", "black", "green"]
}
]
var data1 = [];
function myFunction(){
for(var i = 0; i < data.length; i++){
if (data[i].age < 30)
data1.push(data[i]);
}
console.log(data1);
}
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 100% of JSON Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JSON.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.