Questions tagged [indexof]

The indexof function is commonly used in programming languages such as Java, C#, JavaScript, and more. It is designed to locate the initial occurrence of a specific letter within a string or the first instance of an element in a list.

I find myself a little mixed up with this syntax in JavaScript: `arr.indexOf(searchElement[, fromIndex])`

const beasts = ['ant', 'bison', 'camel', 'duck', 'bison']; console.log(beasts.indexOf('bison')); // expected output: 1 // start from index 2 console.log(beasts.indexOf('bison', 2)); // ...

The hunt is on for greater value within the index

My requirement is to check the text content of a box. If it matches any value stored in an ARRAY, then I have to execute a specific action. var ARRAY1 = ["Saab", "Volvo", "BMW"]; if (select[i].innerHTML.indexOf('ARRAY1') != -1){//code here} Thus, my g ...

Replace the indexOf() method to be called on a null value

I have discovered a way to override functions in JavaScript, such as indexOf(), like this: var indexOf = String.prototype.indexOf; String.prototype.indexOf = function(){ //MY CUSTOM CODE HERE return indexOf.call(this, arguments); }; By doing this ...

Trigger a JavaScript/jQuery alert if the text input field contains a specific string

I am currently facing an issue with a text field (id=#CAT_Custom_244677) that gets populated by a JavaScript date picker. My goal is to display an alert message if the user selects a date that includes '2013' in the text field value. However, I h ...

Locating the exact position of a DOM node within the source document

Purpose In the process of creating a series of 'extractor' functions to identify components on a page using jsdom and nodejs, I aim to organize these identified 'component' objects based on their original placement within the page. Challenge The final s ...

What could be causing the ng-repeat to remove the incorrect item when splicing?

I'm encountering an issue while trying to splice out items in this ng-repeat based on their $index. Although it works perfectly for adding items, when attempting to delete an item using the same code, it ends up removing only the last item of the arra ...