remove repeating elements from json object javascript code example

Example 1: js remove json value duplicates

var data = [{
    "name": "Peter",
    "age": 30,
    "hair color": "brown"
}, {
    "name": "Steve",
    "age": 55,
    "hair color": "blonde"
}, {
    "name": "Steve",
    "age": 55,
    "hair color": "blonde"
}]

 data = this.data.filter((obj, pos, arr) => {
   return arr
     .map(mapObj => mapObj.name)
     .indexOf(obj.name) == pos;
 });

console.log(data);
/*
[{
    "name": "Peter",
    "age": 30,
    "hair color": "brown"
}, {
    "name": "Steve",
    "age": 55,
    "hair color": "blonde"
}]
*/

Example 2: Remove Duplicate objects from JSON

//change is
     while( $row = mysqli_fetch_array( $result ))
    { 
		$response[] = $row;
	}
//with this
while($row = mysqli_fetch_array($result))
{
    $response['id'] = $row['id'];
    $response['name'] = $row['name'];
    $response['password'] = $row['password'];
    $response['email'] = $row['email'];
}