What is the importance of _without() method in JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

_without() 

This method is in the underscore.js library of javascript. It takes two parameters and removes, what are the elements present in the second array, from the first array. It doesn't bother whether the values are true or false, it checks each value one by one and proceeds the task. Make sure that it is case sensitive.

syntax

_.without( array, values);

Example

In the following example, it checks whether the values present in the second parameter are in the first parameter or not and tries to remove the available values.

 Live Demo

<html>
<body>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/0.10.0/lodash.min.js"></script>
</head>
<body>
<script>
   document.write(_.without([5, 6, 4, 8, 9, 9, 0, 1], 0, 9, 1));
</script>
</body>
</html>

Output

5,6,4,8


In the following example, the word java is in both the first and the second parameters and even though it is not removed because the "JAVA" in the second parameter is in the capital case whereas the "java" in the first parameter is in a small case.

Example 

Live Demo

<html>
<body>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/0.10.0/lodash.min.js"></script>
</head>
<body>
<script>
   document.write(_.without([5, 6, "c++", "php", "java", "javascript", 0, 1], 0, "JAVA", 1));
</script>
</body>
</html>

Output

5,6,c++,php,java,javascript
raja
Published on 08-Jul-2019 13:13:54
Advertisements