0

I am completing a homework assignment where I will have to filter an array into a new array for a vehicle with the term of “ford” in it. The assignment wants the format to be in ES6 using the arrow function syntax so something like

const arr = [
{name: “Honda”, type: “Accord”},
{name: “ford”, type: “fusion”},
{name: “Toyota”, type: “Camry”}
]

const newArr = [...arr].filter(value => value === ‘ford’);

Console.log(newArr);

I know this is incorrect and wouldn’t actually get the name of the vehicle that has “ford” in it but I’m giving an example on how they would want it formatted.

dwjohnston
  • 11,163
  • 32
  • 99
  • 194
Marco Chavez
  • 209
  • 1
  • 11
  • 4
    You've almost got it. You don't want the `value` to be `ford` because `value` represents an entire object. You want `value.name` to be `ford`. Also be careful of the quote characters — those look like fancy quotes rather than plain straight ones. That can cause problems. – Mark Jan 15 '19 at 06:41

1 Answers1

3

You need value.name also check the quotes. In this case there may not be any use of the spread operator

const arr = [{
    name: 'Honda',
    type: 'Accord'
  },
  {
    name: 'ford',
    type: 'fusion'
  },
  {
    name: 'Toyota',
    type: 'Camry'
  }
]

const newArr = arr.filter(value => value.name === 'ford');

console.log(newArr);
brk
  • 48,835
  • 10
  • 56
  • 78