Hello !
I have written an array. oldArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
I want to filter the numbers greater than 5.
I proposed a first solution:
let newArray = oldArray.filter(function(x) {
return x > 5;
};
and it worked. it outputs [ 6, 7, 8, 9, 10]
But, since I want to familiarize myself with the arrow functions.
I proposed this as a solution: let newArray = oldArray.filter(x => ({x > 5}));
but apparently it didn’t work. (syntax error)
I try this also: let newArray = oldArray.filter(x => (x > 5));
It didn’t work too.
Can someone please explain me why?
It was my mistake. I work on vscode and I forgot the command + s before outputing my result.
Thank you, it is very helpful.
I really like the last solution