I have the line "2500 - SomeValue". How can I delete everything up to "S" in "SomeValue"?
var x = "2500 - SomeValue"; var y = x.substring(x.lastIndexOf(" - "), // this is where I'm stuck, I need the rest of the string starting from here.
Thanks for any help.
~ ck
Add 3 (length "-") to the last index and leave the second parameter. By default, when passing one parameter to a substring, the end of the line goes
var y = x.substring(x.lastIndexOf(" - ") + 3);
It's simple:
When you omit the second parameter, it just gives you everything to the end of the line.
EDIT: Since you need everything starting with a "-", I added 3 to the starting point to skip these characters.
x.substring(x.lastIndexOf(" - "),x.length-1); //corrected
var y = x.split(" ",2);
. y [2] , .
var y = x.substring(0, x.lastIndexOf(' - ') + 3)
var y = x.slice (x.lastIndexOf ("-"), x.length - 1);
This will return the value as a string, regardless of what value or how much time it has and has nothing to do with arrays.
Source: https://habr.com/ru/post/1715665/More articles:MySQL is another UPDATE else INSERT statement - phpFast integer conversion in Python - performanceId type does not match id - but it does! - objective-cSorting for two columns in a three-column composite index - Oracle - sqlHow to reset netscape.security.PrivilegeManager.enablePrivilege? - javascriptWith browsers that have full page scaling, can I use this function to set the zoom for iframes? - htmlIMetadataExchange ΠΡΠΈΠ±ΠΊΠ° ΠΊΠΎΠ½Π΅ΡΠ½ΠΎΠΉ ΡΠΎΡΠΊΠΈ MEX ΠΏΡΠΈ ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½ΠΈΠΈ ΡΠ»ΡΠΆΠ±Ρ WCF Π² ΠΊΠΎΠ½ΡΠΎΠ»ΡΠ½ΠΎΠΌ ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ - .netIs app.config used only at compile time or is it required at runtime? - .netPrevent data transfer from ASP.NET view to querystring via GET form - asp.netstore objects in a database - databaseAll Articles