DevBitBytedevbitbyte.hashnode.dev·Dec 6, 2023How to write JavaScript indexOf and lastIndexOf array methods from scratchindexOf Returns first index of the found element otherwise -1. Array.prototype._indexOf = function(searchElement, fromIndex = 0) { for(let i = fromIndex; i < this.length; i++) { if(searchElement === this[i]) { return i ...Javascript Mini Challenges & ProjectsJavaScript
Austin Musikuamusiku.hashnode.dev·May 17, 2023H2H: For-loop search vs the .indexOf() methodSearching for a specific element in an array is a common task in programming. Two popular methods for searching arrays in JavaScript are iterating over each element using a for loop and Array.prototype.indexOf(). The former is a simple search algorit...33 readsJavaScript
Mohd Asifmohdasifabid.hashnode.dev·May 16, 2023How to remove the duplicate Elements from an array in JavaScript ?const numArray = [0,1,1,2,2,2,3,3,5,5,5] // input //expected output [0,1,2,3,5] Using the indexOf & filter method indexOf: MDN says, the indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is no...75 readsproblem solving skills
Rajnish sharmarajnisharena.hashnode.dev·Aug 27, 2022Arrays in JavaScriptIn JavaScript, an array is an ordered list of values. Each value is called an element specified by an index. An array is an object that can store multiple values at once. For example, const words = ["India", "Sweden", "Norway", "Iceland"]; Here, word...3 likes·32 readsarray
Vajid Kagdiheyitsvajid.hashnode.dev·Aug 9, 2022How to remove specific item from array by value in Javascript?Find the index of the array element you want to remove using indexOf, and then remove that index with splice. The splice() method changes the contents of an array by removing existing elements and/or adding new elements. const array = [2, 5, 9]; c...76 readsHow TosJavaScript