let object=
[
{
id:`01`,
name:`fish`,
type:`marine`,
},
{
id:`02`,
name:`fish`,
type:`fresh`,
},
{
id:`03`,
name:`fish`,
type:`tank`,
},
{
id:`04`,
name:`animal`,
type:`pet`,
},
{
id:`05`,
name:`animal`,
type:`wild`,
},
{
id:`06`,
name:`animal`,
type:`zoo`,
},
{
id:`07`,
name:`food`,
type:`veg`,
},
{
id:`08`,
name:`food`,
type:`non-veg`,
}
]
let test= object.map((value)=>{
return [value.name,value.id];
})
console.log(test[0]);
I want to fetch all the name and type so I was trying to fetch by giving test[0] and i was expecting that by this i will get all the name which are present inside object but all I am getting name:"fish", id:"01" I was expecting to fetch all name if I type console.log(test[1]; but it didn't gone with the plan
- as i am trying to fetch all name and types by like this
console.log(test[1], test[2]); - expected output like this
fish marine
fish fresh
fish tank
animal pet
animal wild
animal zoo
food veg
food non-veg
- as i want to send all name and type value in my getValue() function as an argument like this so my test[1] contain all the name value and test[2] contain all the type value
getValue(test[1],test[2]);
console.log(test)will show all of them.filter()if you want to get just the elements that havename='fish'and'type='marine'. Or usefind()if you want to return just the first element like that.getValue()looks like?getValue()function @PsyGik like thisgetValue(test[1],test[2])