I am writing a script and I would like to remove some specific elements of an array called uniqueWords
. The elements I want removed are the following: ""
, " "
and "\n"
. To achieve this I tried:
var removeArray = _.remove(uniqueWords, function (word) {return word === '' || word === ' ' || word === '\n'});
var removeArray2 = _.remove(uniqueWords, function (word) {return _.indexOf(['', ' ', '\n'], word) !== -1});
console.log(removeArray);
console.log(removeArray2);
I am using the js class called loadash, but I got the following results:
["", " ", "↵"]
[]
My complete code looks like:
<!DOCTYPE html>
<html>
<script src="lodash.js"></script>
<body>
<p id="demo"></p>
<textarea cols=150 rows=15 id="texto">
"RBD|X|RBD|C|92173~GJHGWO.NAYE" "SAMBORNSiPOSSSTHRa"
"RBD|X|RBD|C|92173~GJHGX4.NAYE" "SAMBORNSiPOSSSTHRa"
"RBD|X|RBD|C|92173~GJHGX6.NAYE" "SAMBORNSiPOSSSTHRa"
"RBD|X|RBD|C|92173~GJHGX8.NAYE" "SAMBORNSiPOSSSTHRa"
"RBD|X|RBD|C|92173~GJHGXA.NAYE" "SAMBORNSiPOSSSTHRa"
"RBD|X|RBD|C|92173~GJHGXC.NAYE" "SAMBORNSiPOSSSTHRa"
</textarea>
<script>
var splitWords = document.getElementById("texto").value.split(/[["\|~]/);
splitWords = document.getElementById("texto").value.split(/[["\|~]/)
//document.write(splitWords.toString());
uniqueWords = _.uniq(splitWords);
console.log(uniqueWords);
var index = uniqueWords.indexOf("");
var index2 = uniqueWords.indexOf(" ");
var index3 = uniqueWords.indexOf("\n");
console.log(index3)
var arrayLength = uniqueWords.length;
var removeArray = _.remove(uniqueWords, function (word) {return word === '' || word === ' ' || word === '\n'});
var removeArray2 = _.remove(uniqueWords, function (word) {return _.indexOf(['', ' ', '\n'], word) !== -1});
console.log(removeArray);
console.log(removeArray2);
</script>
I would like to appreciate any suggestion to achieve this.