indexof

indexOf returning -1 despite object being in the array - Javascript in Google Spreadsheet Scripts

心已入冬 提交于 2019-12-05 04:08:10
I am writing a script for a Google Docs Spreadsheet to read a list of directors and add them to an array if they do not already appear within it. However, I cannot seem to get indexOf to return anything other than -1 for elements that are contained within the array. Can anyone tell me what I am doing wrong? Or point me to an easier way of doing this? This is my script: function readRows() { var column = SpreadsheetApp.getActiveSpreadsheet().getRangeByName("Director"); var values = column.getValues(); var numRows = column.getNumRows(); var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet =

Is using a Regular Expression faster than IndexOf?

≡放荡痞女 提交于 2019-12-05 02:54:27
I have an app running which looks at items in a queue, then based upon certain keywords a category is applied - then it is inserted into a database. I'm using IndexOf to determine if a certain keyword is present. Is this the ideal way or would a RegEX be faster? There's about 10 items per second being processed or so. For just finding a keyword the IndexOf method is faster than using a regular expression. Regular expressions are powerful, but their power lies in flexibility, not raw speed. They don't beat string methods at simple string operations. Anyway, if the strings are not huge, it

Swift: cannot convert value of type to @noescape while call indexOf, after filter using filter function

你说的曾经没有我的故事 提交于 2019-12-04 22:42:02
In Swift 2, I'm receiving an error: Cannot convert value of type '[String:AnyObject]' to expected argument type '@noescape ([String:AnyObject])' throws -> Bool" //today = NSDate() //array : [[String:AnyObject]] // I use if let because of we might now get element in the array matching our condition if let elementOfArray = array.filter({$0["id"] as? Int == anotherDictionary["matchID"] as? Int && ($0["nextFireDate"] as? NSDate)?.compare(today) == NSComparisonResult.OrderedAscending}).first { let index = array.indexOf(elementOfArray) // error here } What I'm doing wrong? I can't understand. :/ My

Javascript Arrays In IE 8 issue

戏子无情 提交于 2019-12-04 18:54:13
As per what I know, arrays in Javascript is nothing but the combination of methods and objects. Now my task is to display the values of array (say y_array ) I have used for(x in y_array) and then displayed the value. In mozilla and in IE its working fine, but in IE it displays the first element of array with index as indexOf and value is indexOf(obj, from) which i dont want. I tried if(x!='indexOf') { display the array value ; } It worked and things were fine but there is extensive use of arrays been displayed and I am looking for some permanent fix rather than this hardcoded one. Can anyone

Looping Through String To Find Multiple Indexes

一个人想着一个人 提交于 2019-12-04 14:15:53
I am trying to figure out the most efficient way of looping through a string and finding all indexes of a certain letter. I have used $word_or_phrase.indexOf( $letter ); to find a single index of a letter, but the letter is in $word_or_phrase multiple times. Would the most efficient way to do this be to build an array of all the indexes until .indexOf returns -1? Or how would you suggest me finding all the the indexes? I have already taken time and found this: Javascript str.search() multiple instances This works, but to me doesn't seem efficient when dealing with more than 2 indexes. What if

strange string.IndexOf behavour

我是研究僧i 提交于 2019-12-04 13:47:39
问题 I wrote the following snippet to get rid of excessive spaces in slabs of text int index = text.IndexOf(" "); while (index > 0) { text = text.Replace(" ", " "); index = text.IndexOf(" "); } Generally this works fine, albeit rather primative and possibly inefficient. Problem When the text contains " - " for some bizzare reason the indexOf returns a match! The Replace function doesn't remove anything and then it is stuck in a endless loop. Any ideas what is going on with the string.IndexOf? 回答1:

Need to reset just the indexes of a Javascript array

◇◆丶佛笑我妖孽 提交于 2019-12-04 06:16:28
I have a for loop which returns an array. Return: 1st loop: arr[0] arr[1] arr[2] arr[3] Here the length I get is 4 (Not a problem). Return: 2nd loop arr[4] arr[5] arr[6] arr[7] arr[8] Here the length I get is 9 . What I want here is the actual count of the indexes i.e I need it to be 5 . How can I do this. And is there a way that when I enter each loop every time it starts from 0 so that I get proper length in all the loops? This is easily done natively using Array.filter: resetArr = orgArr.filter(function(){return true;}); You could just copy all the elements from the array into a new array

Lua - get indexOf string

被刻印的时光 ゝ 提交于 2019-12-04 05:44:20
I am stuck with a problem in Lua to check whether the string value is not presented in another string. That's how I likely will do it in Javascript: 'my string'.indexOf('no-cache') === -1 // true but in Lua I'm trying to use string module which gives me unexpected response: string.find('my string', 'no-cache') -- nil, that's fine but.. string.find('no-cache', 'no-cache') -- nil.. that's weird string.find('no-cache', 'no') -- 1, 2 here it's right.. strange.. As has already been mentioned, - is a pattern metacharacter, specifically : a single character class followed by '-', which also matches 0

c# substring indexof

霸气de小男生 提交于 2019-12-04 04:42:46
i have a string which looks like this - "FirstName||Sam LastName||Jones Address||123 Main ST ..." (100 more different values) I want to find only Sam and Jones from the entire string. so string firstname = originalstring.substring ... etc. Does anyone know how I can do this? ADDITION - I think i forgot to mention couple of things. FirstName||Sam\r\n MiddleName||\r\n LastName||Jones\r\n .... So now if i count the number of characters that wont help me, cause could need more items other than just firstname and lastname . Use Regular expressions : string myString = "FirstName||Sam LastName||Jones

IE: indexOf results in “object doesn't support this property or method”

对着背影说爱祢 提交于 2019-12-03 22:13:15
I have the following if statement: if (buyArray.indexOf(dealWith,0) != -1){ Which is breaking in ie (ie 8 on XP) with "object doesn't support this property or method". Anyone have a work around for this? yeah, IE<9 doesn't support indexOf . You can implement a shim like the one showed here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf Or if you already using jQuery you can use inArray . Also underscore has an implementation for it. Simply changed to the use jQuery.inArray. Thanks to ZER0 for the heads up if ($.inArray(dealWith, buyArray) != -1) { 来源: https