How to use some() method In Javascript
Accessing those values from the JSON array where some of the conditions are met in the array. Some() method checks whether at least one of the elements of the array satisfies the condition checked by the argument method.
Example: Using some() method to access values from the array.
Javascript
let jsonArray = [ { "Name" : "w3wiki" , "Location" : "Noida" }, { "Courses" : [ "DSA self-paced course" , "DevOps Bootcamp" , "GATE preparation course" ], "Topics" : [ "Web development" , "Artificial Intelligence" , "Machine Learning" , "Data Science" , "Algorithms" ] } ]; let Item = null ; jsonArray.some(item => { if (item.Name === "w3wiki" ) { Item = item; // This will exit the loop once the item is found return true ; } }); if (Item !== null ) { console.log(Item); } else { console.log( "Item not found" ); } |
Output
{ Name: 'w3wiki', Location: 'Noida' }
How to Get a Value from a JSON Array in JavaScript ?
We are going to iterate or access the value of a JSON array in JavaScript. There are several ways and techniques to access values from the JSON Array which are explained in detail below and are further divided into several possible techniques.
Table of Content
- Using the array[index] method
- Using the array[key] method
- Using the array.slice method
- Using for…of the loop
- Using forEach()
- Using the map() method
- Using filter() method
- Using the find() method
- Using findIndex() method
- Using some() method
- Using recursive traversal of JSON array
- Using the custom reduce method
- Using custom classes
Contact Us