Questions tagged [indexof]

indexof is a method in programming languages like Java, C#, JavaScript, etc. that returns the first occurrence of a letter in a string, or the first occurrence of an element in a list.

indexof returns the first occurrence of a letter or a substring in a string, or the first occurrence of an element in a list.

1975 questions
0
votes
2 answers

jQuery - find text in textarea

I want to write a validation for a textarea to prevent to type some words, well for example if you type Viber on textarea it will remove that and then alert, my problem is this code only work when you type viber first! if you type for ex: I like…
Pedram
  • 15,766
  • 10
  • 44
  • 73
0
votes
2 answers

Change particular characters (escape characters) in a string by using regex or indexOf in Javascript

I'm trying to change particular characters such as [ ', ", \ ] because I have a problem during INSERT. For example, the string I'm saying "Hi" will be I\'m saying \"Hi\". So basically this method is adding backslash in front of the characters. But…
KimCrab
  • 2,231
  • 4
  • 15
  • 20
0
votes
4 answers

JavaScript Array indexOf Array?

I was wondering how I can check this. Example: var products = [ { title: 'Product 1', categories: ['One', 'Two', 'Three'] }, { title: 'Product 2', categories: ['Three', 'Four'] } ]; var categories =…
user482954
0
votes
1 answer

JavaScript - for loop Iterations not working with indexOf function

var text = "Uncle Bob was in World War II. Many people believe World War II was the most destructive war to date."; var replace = text.indexOf("World War II"); for (var i = 0; i < text.length; i++) { if (replace[i] !== -1) { text…
BobRoss
  • 53
  • 1
  • 11
0
votes
1 answer

Javascript: Regex vs IndexOf when scanning for a list of keywords

I see that indexOf is faster when you're scanning against one word according to the solution here JavaScript: indexOf vs. Match when Searching Strings? However, what if you have a list of say 5 keywords and you want to count the occurrence of each…
Arrow
  • 691
  • 2
  • 7
  • 15
0
votes
2 answers

JavaScript Array indexOf() Method not working

I am trying to find an item in an array. I get only -1 for my variable a, so the item was not found in my array, but the item is definitely in array. var sortiment = []; var geschmack = []; var kategorie = []; function filterOptions(eigenschaft,…
Alex
  • 50
  • 1
  • 6
0
votes
1 answer

JavaScript indexOf() function fails in VB.Net

This code works well in most (all?) browsers: myDate = new Date(); alert(myDate.toString().indexOf("(")); However, when executed within a VB.Net WebBrowser control, it returns -1. Why is that?
iSofia
  • 1,412
  • 2
  • 19
  • 36
0
votes
2 answers

Using indexOf() with an array of type UIButton

I am following a tutorial called "Starting Developing iOS Apps (Swift)" at this link. https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson5.html#//apple_ref/doc/uid/TP40015214-CH19-SW1 I have…
killianjackson
  • 115
  • 1
  • 6
0
votes
7 answers

Javascript indexOf object not found

I'm trying to find the index of my object inside an array in Javascript. This is the code I'm using, this returns -1 so it's not found. But it's there var index = this.state.users.indexOf(user); The object I'm comparing with is identical to the…
Miguel Stevens
  • 8,631
  • 18
  • 66
  • 125
0
votes
1 answer

Implement my own recursive version of the indexOf method

So I'm trying to write recursive method indexOf which returns the starting index of the first occurrence of the second String inside the first String (or -1 if not found).For example, the call of indexOf (“Barack Obama”, “bam”) would return 8. Also…
Anton9988
  • 377
  • 1
  • 4
  • 17
0
votes
1 answer

Breakdown of indexOf function

Can someone explain this solution to me? A friend helped me, but he just wrote it all out and didn't explain it. Now, I'm really confused :( _.indexOf = function(array, target){ var result = -1; _.each(array, function(item, index) { if…
Rory Perro
  • 441
  • 2
  • 7
  • 16
0
votes
2 answers

.on('keyup') calculate the .indexOf a certain word or phrase

I have a textarea that on keyup calls a function when a certain word or phrase has been entered, but also calls another function which undoes the initial function, if the word or phrase is then deleted. var phraseList = [ "foo foo", …
rxssmcdxwell
  • 109
  • 1
  • 14
0
votes
1 answer

Get DataGrid row index of value?

What I'm trying to do is get the row index from content. I have a DataGrid with 2 columns, one for an Identifier (as DataGridTextColumn) and another for Refferer that refers to specific identifiers (as DataGridTemplateColumn label, it has a MouseUp…
Sakuya
  • 660
  • 5
  • 23
0
votes
0 answers

How to get the offset of a text in HTML tag and all the parents to the root tag in PHP?

I extract from an article for example the publicationYear, title and authors like this: $aut = $xpath->query("//table[@cellpadding='6']//b[1]"); $authors = array(); foreach($aut as $node) $authors[] = $node->nodeValue; $title =…
0
votes
1 answer

Loop counter resetting to -1

This is a course project for a simple search counter for the word "Wrox" in a string. My code: var myString = "Welcome to Wrox books. "; myString = myString + "The Wrox website is www.wrox.com. "; mystring = myString + "Visit the Wrox website…
xa3d
  • 1
  • 1
1 2 3
99
100