Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
For example I have these array
total = [[0,1],[0,2]] arr = [0,2]
apparently total includes the arr
total
arr
However total.indexOf(arr) return -1
total.indexOf(arr)
-1
Is there any good way to solve this?
[0,2] !== [0,2]
[] !== []
total.some(r => r.every((value, index) => value === arr[index]))
Try JSON.stringify
JSON.stringify
const total = [[0,1],[0,2]] const arr = [0,2] const index = total.findIndex(item => JSON.stringify(item) === JSON.stringify(arr)) console.log(index)
Add a comment
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
[0,2] !== [0,2]- in fact[] !== []total.some(r => r.every((value, index) => value === arr[index]))it might work