I have an array in which I have strings, in this I want to slice the array after I get "test?", but my logic of slicing isn’t working.
let input = ['hello', 'choose', 'test1', 'test?', 'yes,', 'no'];
let output = input.slice(input.indexOf('?') + 1, input.length);
console.log(output);
Desired Output:
["test?","yes"]
>Solution :
You need to find the index of the array element where ? is there, then we can slice it, also this will find the first occurrence only!
let input = ['hello', 'choose', 'test1', 'test?', 'yes,', 'no'];
let output = input.slice(input.findIndex(x => x.includes('?')) + 1, input.length);
console.log(output);