ReactJs Remove Duplicate Values from Array
There are many ways to remove duplicate items from Array. Here in this tutorial, we are going to explain the simplest and smartest way to remove the duplicate items from array. You can also use our online editor to edit and remove duplicate items from array.
ReactJs Remove Duplicate Values from Array JavaScript
Here is the most efficient native way to remove duplicate values from Array in ReactJs.
Example:
<div id="root"> </div> <script type="text/es2015"> function MyFunction() { var myArray = ['100', '120', '130', '140', '500', '100', '120', '140']; var result = []; result = myArray.filter(function(item, pos, self) { return self.indexOf(item) == pos; }) var items = result.map((item) => item+',' ); return ( <p>{items}</p> ); } ReactDOM.render( <MyFunction />, document.getElementById('root') ); </script> |
In the above example we have used the native JavaScript to remove the duplicate items from an array. Output of above example-
Advertisements
User Ans/Comments
Nice Job! Keep It up
jhon