Skip to content

$state() of Array : incorrect behavior of indexOf()/findIndex() with object #11556

@adiguba

Description

@adiguba

Describe the bug

When we used an $state([]), some basic function of Array have an incorrect behavior with object.
It seems that all equality operations fail, as the object in the array is a proxy.

	let array = $state([]);
	
	const obj = { data: "any value" };
	array.push(obj);
	
	console.log( array[0] === obj );                 // false !!!
	console.log( array.indexOf(obj) );               // -1 !!!
	console.log( array.findIndex(n => n === obj) );  // -1 !!!

It’s really disturbing and not easy to understand...

Reproduction

Exemple in REPL : the buttons addRandomNumber, addRandomString and addRandomObject add a number/string/object in an array, and logs the index.

This works as espected for number and string, but fails for objects.

REPL

Logs

No response

System Info

REPL

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions