Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
// numbers array
const numsArr = [23, 45, 56, 78];
// get the element's index position
// if number is not present the method will return -1
const indexToDelete = numsArr.indexOf(100);
// remove the element from the array
// by passing index position as the first argument to the splice() method
// and the number of elements to delete from the index psotion as the second argument
// in our case wee need to delete only one element from the index psotion
// Also, check is the indexOf() mehtod returns -1
// if it returns -1 don't do the splice() opeartion
if (indexToDelete > -1) {
  numsArr.splice(indexToDelete, 1);
} else {
  console.log("element not found in the array");
}
console.log(numsArr); // [23, 45, 56, 78]
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers