Hey, I’m trying to use the Filter over an Array, but although when debugging it appears to be filtering, the end result is the same original array. Ex below:
let orig_arr = ["A", "A#/Bb", "B", "C", "C#/Db", "D", "D#/Eb", "E", "F", "F#/Gb", "G", "G#/Ab"];
let new_arr = this.orig_arr.filter((elm) => {
if(elm.indexOf("/")!=-1) {
elm = elm.split("/")[0];
}
return tun;
})
tun is not defined? Maybe you wanted to return the direct result of elm.indexOf("/") So there is not even a need to have if. just return elm.indexOf("/") != -1
Or if you want cleaner code: orig_arr.filter(el => !el.includes('/'))
By looking closer at your question, I see that filter is not what you want
In this case you need a .map. You only use filter if you actually want to remove from an array.