+ Start a Discussion
Phuc 2Phuc 2 

Nested array get field value

Hello All,
I created a LWC and I need to get a field value but its inside a nested array.  How would I get the Name value in the below example?

mukesh guptamukesh gupta
Hi  Puch,

Below is example for your understanindg you can use for your code:-
const myObj = {
  name: "John",
  age: 30,
  cars: [
    {name:"Ford", models:["Fiesta", "Focus", "Mustang"]},
    {name:"BMW", models:["320", "X3", "X5"]},
    {name:"Fiat", models:["500", "Panda"]}


 for (let i in myObj.cars) {
  x += "<h1>" + myObj.cars[i].name + "</h1>";
  for (let j in myObj.cars[i].models) {
    x += myObj.cars[i].models[j];

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.