Navigate back to the homepage

how to get value from json array in javascript?

Infinitbility
JavaScript
August 12th, 2022 · 1 min read
how to get value from json array in javascript?

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.

1let arr = ["Infinitbility", "aGuideHub", "SortoutCode"];
2
3// used `index` number
4console.log(arr[1]);
5
6// Output
7// aGuideHub
8
9
10// used `for` loop
11for(let value of arr) {
12 console.log(value);
13}
14
15// Output
16// 'Infinitbility'
17// 'aGuideHub'
18// '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.

1let arr = ["Infinitbility", "aGuideHub", "SortoutCode"];
2
3console.log(arr[0]);
4
5// Output
6// 'Infinitbility'
7
8console.log(arr[2]);
9
10// Output
11// 'SortoutCode'
12
13console.log(arr[5]);
14
15// Output
16// 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.

1let arr = ["Infinitbility", "aGuideHub", "SortoutCode"];
2
3for(let value of arr) {
4 console.log(value);
5}
6
7// Output
8// 'Infinitbility'
9// 'aGuideHub'
10// '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.

1let arr = [
2 {
3 name: "Infinitbility"
4 },
5 {
6 name:"aGuideHub"
7 },
8 {
9 name:"SortoutCode"
10 }
11];
12
13for(let value of arr) {
14 console.log(value.name);
15}
16
17// Output
18// 'Infinitbility'
19// 'aGuideHub'
20// 'SortoutCode'

I hope it helps you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to remove item from object in react js?

how to remove item from object in react js?

An example of remove or delete item from object in react js with the step-by-step guide.

August 10th, 2022 · 1 min read
how to remove item from object in react native?

how to remove item from object in react native?

An example of remove or delete item from object in react native with the step-by-step guide.

August 10th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]