Just negate it.
filteredResult = filteredResult.filter(e => !e.selectedFields.includes("Red"))
Answer from tremby on Stack OverflowJust negate it.
filteredResult = filteredResult.filter(e => !e.selectedFields.includes("Red"))
You can negate the includes result or even cleaner just by using the indexOf property:
const arr = [1, 2, 3];
const notIncludes1 = (arr, val) => !(arr.includes(0));
const notIncludes2 = (arr, val) => arr.indexOf(val) === -1;
You can't compare objects directly, but using this method , you can compare them with JSON.stringify.
let list1 = [{
name: "object1"
},
{
name: "object2"
},
{
name: "object3"
},
{
name: "object4"
}
]
var contains = list1.some(elem =>{
return JSON.stringify({name: "object1"}) === JSON.stringify(elem);
});
if (contains) {
document.write('contains')
} else {
document.write('doesnt')
}
You can try following
let list1 = [{name:"object1"},{name:"object2"},{name:"object3"},{name:"object4"}]
if (list1.some(({name}) => name === "object1")) {
document.write('contains')
} else {
document.write('doesnt')
}
Hi All,
Trying to get a little function going where when a client leaves a * or symbol in a certain table cell, the background color of that table cell will change.
This is all in a `if is_page())` and I'm also using ACF.
I receive this error in Chrome Console:
Uncaught TypeError: cells.includes is not a function
Any assistance would be great!
UPDATE: SOLUTION IS BELOW
Solution:
<script type="text/javascript">
function cellColorBlue() {
var tableCells = [...document.querySelectorAll("td")];
for (cell of tableCells) {
if(cell.innerText.includes("*")) {
cell.style.backgroundColor = "#63b2df";
}
}
}
function cellColorGreen() {
var tableCells = [...document.querySelectorAll("td")];
for (cell of tableCells) {
if(cell.innerText.includes("^")) {
cell.style.backgroundColor = "#9ce158";
}
}
}
cellColorBlue();
cellColorGreen();
</script>I just stumbled across this: https://www.reddit.com/r/typescript/s/h9MOx2opXV
And it brought back a thought I’ve had a few times.
Is there a good reason Array.includes restricts the search argument to extending the type of the array, given that (to my understanding), any value can be passed to includes and checked against any contents.
Unless I’m missing something it feels like it would be much more useful as a type guard!