Online HTML Editor
Javascript Online Compiler
index.html
Change Theme
Compress code
Uncompress code
Download Code
Clear Code
Copy Code!
RunĀ
Click to run or ctrl+s
Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Article - remove object from array using key 2</title> </head> <body> <h2>Removing object from array using key with <code>splice</code> method.</h2> <p>The javascript code here finds employe with salary less than 25000 and removes it from the array.</p> <p>Press <kbd>F12</kbd> to open the console and see the output of the program.</p> <script> let employees = [ { id: 1, salary: 25000, shift: "day" }, { id: 2, salary: 38000, shift: "day" }, { id: 3, salary: 23000, shift: "night" }, { id: 4, salary: 20000, shift: "day" }, { id: 5, salary: 45000, shift: "night" } ]; // remove all worker with less than 25000 salary for (let i = 0; i < employees.length; i++) { if (employees[i].salary < 25000) { employees.splice(i, 1); i--; } } console.log(employees); </script> </body> </html>
RunĀ