• JavaScript codes to detect if a substring is exists in a string.
var str = "hello world";
var substr = "world";
// This codes will return `true` is `substr` is in `str`.
console.log(str.indexOf(substr) > -1);
  • JavaScript to detect multiple indexes in an array (each for the same element).
// Function to return multiple indexes in an array for found element.
function indexesOf (_array, _element) {
  var indexes = [];
  for (var i = 0; i < _array.length; i ++) {
    if (_array[i] == _element) indexes.push(i);
  }

  return indexes;
}
  • Multiple replace() in JavaScript.
str = "asdasd".split(replaceThisString).join(withThisString);
  • How to make sure that a JavaScript array is unique.
arr = Array.from(new Set(arr));
"asdasd".split("");