What is the difference between the two JavaScript expressions? [duplicate]

I am using filter method of JavaScript to remove the duplicate entries and I am using the below syntax:

var dataArray = ['g','o','o','g','l','e']
dataArray.filter((value, index) => dataArray.indexOf(value) === index)

The above code works fine and returns me an array by removing the duplicate values. But, when I add a { curly braces after arrow function it returns an empty array.

var dataArray = ['g','o','o','g','l','e']
dataArray.filter((value, index) => { dataArray.indexOf(value) === index })

I am unable to figure out what's the actual difference between both of the syntaxes and why the second one is returning me an empty array.



Read more here: https://stackoverflow.com/questions/66334011/what-is-the-difference-between-the-two-javascript-expressions

Content Attribution

This content was originally published by HarshSharma at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: