I have a Array
var arr=[{t: "Lokanath", v: 0},
{t: "Das", v: 1}]
Is there any way that i can get the Record t: "Das", v: 1
based on the value of v i.e. v:1
I have a Array
var arr=[{t: "Lokanath", v: 0},
{t: "Das", v: 1}]
Is there any way that i can get the Record t: "Das", v: 1
based on the value of v i.e. v:1
The
filter()
method creates a new array with all elements that pass the test implemented by the provided function.
You can use filter()
in the following way:
var a=[{text: "Lokanath", value: 0, id: 100},
{text: "Das", value: 1, id: 101}];
var das = a.filter(p => p.text=='Das');
console.log(das[0]);
Please Note: Since filter()
returns an array, you have to use index to take the object.
var arr=[{text: "Lokanath", value: 0, id: 100},
{text: "Das", value: 1, id: 101}]
arr.find(d => d.text == "Das")
you can use filter method to do that.
var arr=[{text: "Lokanath", value: 0, id: 100},{text: "Das", value: 1, id: 101}];
console.log(arr.filter(o => o.text=='Das')[0]);