How to use for…of the loop In Javascript
Accessing values from the JSON array by Iterating through each element of the JSON array. for…of statement iterates over the values of an iterable object (like Array, Map, Set, arguments object, …,etc), executing statements for each value of the object.
Syntax:
for ( variable of iterableObjectName) {
// code block to be executed
}
Example: Using for…of loop to access value.
Javascript
let jsonArray = [ { "ComapnyName" : "w3wiki" , "Location" : "Noida" }, { "Courses" : [ "DSA self paced course" , "DevOps Boot camp" , "GATE prepration course" ], "Topics" : [ "Web Devlopment" , "Machine Learning" , "Artifical Intelligence" ] } ]; for (let element of jsonArray) { console.log(element); } |
Output
{ ComapnyName: 'w3wiki', Location: 'Noida' } { Courses: [ 'DSA self paced course', 'DevOps Boot camp', 'GATE prepration course' ], Topics: [ 'Web Devlopment', 'Machine Learnin...
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