0

I have a multidimensional array as following.

[['Base: Values','55','98','90.8'],['Value First','55','98','90.8'],['Top','55','98','90.8'],['Bottom','55','98','90.8']]

I want to remove entire values if it includes 'Top' or 'Bottom', so that i will get a result like this:

[['Base: Values','55','98','90.8'],['Value First','55','98','90.8']]

Somebody give me a solution please. Thanks in advance.

1 Answer 1

1

You can filter the array, providing a function to determine if an element should be included or not :

array.filter(e => !e.includes('Top') && !e.includes('Bottom'));

Example:

const data = [
    ['Base: Values','55','98','90.8'],
    ['Value First','55','98','90.8'],
    ['Top','55','98','90.8'],
    ['Bottom','55','98','90.8']
]
const filtered = data.filter(e => !e.includes('Top') && !e.includes('Bottom'));
console.log(filtered)
console.log(data)

EDIT: To exclude if any string in array values contains a specific part, you could change the predicate to check if at least one string contains the part:

array.filter(e => !e.some(i => i.includes('part to find')));

Example:

const data = [
    ['Base: Values','55','98','90.8'],
    ['Value First','55','98','90.8'],
    ['Top','55','98','90.8'],
    ['Bottom','55','98','90.8']
]
const filtered = data.filter(e => !e.some(i => i.includes('Value')));
console.log(filtered)
console.log(data)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer. Its working fine if i am checking exact word. What i have to do to remove by checking a portion only. In the above example if i want to delete ['Base: Values','55','98','90.8'] by checking 'Base ' only??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.