I'm working with two arrays that has correlated the values, which mean that arrayX[1] correlate with arrayY[1], and arrayX[2] correlate with arrayY[2] and so on.
I now need to filter that arrayX, to match or contains a given value, and only displays the arrayX filtered and arrayY that matches.
I've tried to create an array/map with key - value that I found this link Take object out of array based on attribute value, and then filter with '.find' but I couldn't has the expected result.
When I call the function to filter I pass a value, for example I'm passing a string '2010'
My arrayX has:
(10) ["Dec 2008", "Feb 2010", "Apr 2010", "Jul 2010", "Dec 2010", "Feb 2011", "Apr 2012", "Jul 2013", "Mar 2014", "May 2017"]
My arrayY has:
(10) [1, 7, 4, 1, 10, 11, 4, 8, 7, 10]
so, for the output I need
arrayX to be ["Feb 2010", "Apr 2010", "Jul 2010", "Dec 2010"] and
arraY to be [7, 4, 1, 10].
My typescript code that expects a value and filter is:
filtr(dt){
console.log(dt);
console.log(this.arrayX);
console.log(this.arrayY);
//Array contains x and y values at the correct position
let array = [
{y: this.Yvalues, x: this.Xvalues}
];
let item : any = array.find(i => i.x.find(dt));
//new filtered x and y values on array
console.log(item)
}
I can't figure out how am I going to do this... I thought that the key -> value was a good solution, but I can't even have an output.. Sorry if I'm missing something easy.