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
1 answer

Index of element of nested array

I need to create a journey planner : I have three lines with multiples stops and all of them have one in common. This is what I've been doing so far with javascript; don't know if it make sense at all. What I tried to do is ...defining my start…
user6055408
0
votes
2 answers

Cant get indexOf statement to work

Ultimately I am prompting the user for a guess, which is then ultimately changed so regardless of what the user inputs it will always Capitalize the first letter and make the rest lowercase. (Im doing this so if the user types in a guess the string…
Nate E.
  • 125
  • 1
  • 1
  • 10
0
votes
1 answer

Checking input variables against array

Trying to check input variable (sGuess) against my array (sportsArray) ... var name works fine then when I have it check that variable (sGuess) that the user inputs against the array (sportsArray) I always get the following in console. Loop 1…
Nate E.
  • 125
  • 1
  • 1
  • 10
0
votes
0 answers

swift: print string instead of IndexOf an array

My first array is for English words and my second array contains Spanish words. When the user enters a word in English from array1 the output will be the IndexOf array2. Instead of displaying the IndexOf array2 "1" how can I print the String in…
Miguel
  • 213
  • 1
  • 3
  • 12
0
votes
0 answers

Using indexOf to search the document.referrer for a home domain and act upon this

I'm trying to add an on-page "back" link that will only appear if the referrer was the home domain. I have been through a number of threads on here which have been very helpful, but my code does not work despite being a combination of others'…
0
votes
1 answer

Compare 2D lists and return index where they differ

I want to compare the elements of two similar lists and return the index where they differ. The lists will only differ at one position. def coord(a,b): for i in range(0,3): for j in range(0,3): if a[i][j] != b[i][j]: …
Fred
  • 13
  • 1
0
votes
0 answers

".indexOf" an array of Custom Objects

In my app I have an array of custom Objects.The structure of each row looks like this when I append them: self.listOfParticipants.append(ParticipantInfo(participantUser: "userID", participantName: "userName", participantIconName: partiImage!)) I…
Victor Rius
  • 4,566
  • 1
  • 20
  • 28
0
votes
2 answers

Finding an Array within an Array using IndexOf of JavaScript

I am trying to do a very simple indexOf search without success. I have a two dimensional Array like this: var fruits = new Array([]); fruits.push(["Banana", "Orange", "Apple", "Mango"]); fruits.push(["Apple", "3Orange", "Amar",…
AnR
  • 1,809
  • 3
  • 26
  • 45
0
votes
5 answers

Seeing if a index is negaitve

I am writing a program for my structured programming class and we have to take a input string, break it into 3 substrings and then check to see if all three names are there. I have the string broken up at the spaces and now I just need to check that…
jzaunegger
  • 11
  • 3
0
votes
3 answers

Need the Index No of an Array List, by giving the certain text of the element String

I want to get the particular index of the array list, by using only contained text. Say suppose, I have arraylist as Test = {"LabTechnician","SeniorLabTechnician_4","Pathologist","SeniorLabTechnician_6"} If want the index nos of both the…
Thippana
  • 21
  • 1
  • 6
0
votes
1 answer

indexOf(String) linked list char logic error

First year CS student. Ive tried to implement an indexOf(String) method in my custom MyStringbuilder class (in this case with a linked list of char). I cant get the right output for finding the query string at the front or not finding it but…
0
votes
1 answer

linked list of chars - int indexOf(String)

How would you approach creating the method int indexOf(String str) if creating your own StringBuilder class as a linked list of char's. Would you loop through with a bunch of logic or would it be easier to parse the StringBuilder object and then…
0
votes
2 answers

Is this a correct implementation of a .indexOf? Javascript

I've tested my implementation of .indexOf, and it seems to work on my test cases, but I've seen other solutions where they add in the if condition array[i] === elem && notFound === -1. What is the purpose of the second condition? This is my…
TheRealFakeNews
  • 7,512
  • 16
  • 73
  • 114
0
votes
0 answers

Javascript document.referrer is looping

I'm a new programmer so I'm open to learning more standard ways of programming. Currently: I'm having an issue with redirecting users who come from certain sites. This is an intranet website I'm working on. //Redirect to the correct FAQ page var…
Matt
  • 135
  • 3
  • 17
0
votes
1 answer

How is indexOf returning the position of this example, shouldn't the result be -1?

I know that indexOf searches the position of a value in a string / array then returns the position but I thought the it must be an exact match even if there's spaces. But I was reading this and I am confused why it's returning true even if the…
Dora
  • 6,776
  • 14
  • 51
  • 99