Hi Friends đź‘‹,

Welcome To Infinitbility! ❤️

To get value from json array in javascript, we have two ways

  1. use index number to single specfic value from json array
  2. use for loop to get all values from json array

Let’s see short example to use index number and for loop on json array.

let arr = ["Infinitbility", "aGuideHub", "SortoutCode"];

// used `index` number
console.log(arr[1]);

// Output
// aGuideHub


// used `for` loop
for(let value of arr) {
    console.log(value);
}

// Output
// 'Infinitbility'
// 'aGuideHub'
// 'SortoutCode'

Today, I’m going to show you How do I get value from json array in javascript, as above mentioned, I’m going to use the above-mentioned Array.length property.

Let’s start today’s tutorial how do you get value from json array in javascript?

Javascript get value from json array example

Here, we will take sample json array variable with some data and use index to get single, specfic value from json array.

let arr = ["Infinitbility", "aGuideHub", "SortoutCode"];

console.log(arr[0]);

// Output
// 'Infinitbility'

console.log(arr[2]);

// Output
// 'SortoutCode'

console.log(arr[5]);

// Output
// undefined

Javascript get values from json array example

Here, we will take sample json array variable with some data and use for loop to all item of json array.

let arr = ["Infinitbility", "aGuideHub", "SortoutCode"];

for(let value of arr) {
    console.log(value);
}

// Output
// 'Infinitbility'
// 'aGuideHub'
// 'SortoutCode'

Javascript get values from json array of object example

Here, we will take sample json array of object variable with some data and use for loop to all item of json array of object.

let arr = [
    {
        name: "Infinitbility"
    },
    { 
        name:"aGuideHub"
    }, 
    {
        name:"SortoutCode"
    }
];

for(let value of arr) {
    console.log(value.name);
}

// Output
// 'Infinitbility'
// 'aGuideHub'
// 'SortoutCode'

I hope it helps you, All the best đź‘Ť.