Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Filter multidimensional array based on another array

I am new to JS. I have multidimensional array.

var myList = [{"Fund":"Edelweiss1","Rank":10},{"Fund":"Edelweiss","Rank":5}, {"Fund":"Edelweiss3","Rank":3}]

I want to filter "Rank" based on another array.

var rngarray = [6,10];

Filtering on rank should be >=6 and <=10

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried this – myList.filter(function (v) {rngarray.includes(v["Rank"])}) but does not work.

>Solution :

Use Array.prototype.filter():

var myList = [{"Fund":"Edelweiss1","Rank":10},{"Fund":"Edelweiss","Rank":5}, {"Fund":"Edelweiss3","Rank":3}];

var rngarray = [6,10];

var filtered = myList.filter(item => item.Rank >= rngarray[0] && item.Rank <= rngarray[1]);
console.log(filtered);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading