Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "indexof"
-
5 months ago we are using string for identifying some stuff:
var abc = "badstuff/abc"
var isBad = abc.indexOf("badstuff")>-1
// fine
we later switched to id, so
var abc = 13;
var isBad = abc.indexOf("badstuff") > -1;
// well this is wrong
so I approached the colleague and said to her that we use id now, indexOf("badstuff") no longer works, and id can be arbitrary, like 3245.
-- ok ill do it.
I dont know 3245 looks really like a special id or not. this is the outcome:
var abc = 13;
var isBad = abc.indexOf(3245) > -1;
lol.1 -
!rant
Before I left my other company I was in the midst of finishing one project and I was ansious to finish everything to leave as a rockstar. Now, one of my js scripts brought a huge and long json response that had many nested items and arrays and whatnot. Instead of properly destructuring or finding a particular piece that went similarly to "status": "Verify input"(that was nested unser a shitload of items) i did the unspeakable......i stringified the whole object and just used indexOf.
I still feel guilty over it...but it works :P thing is, if it returns that it means that the user entered an invalid status into the app (it was an inventory application) but it works :P
Oh well. Mind you they thought it was going to take months and I finished in 1 week so yay. -
I detest using `indexOf` to check if a string contains a substring so much I could write a rant about it.
Or is there a better way? One google search later: ES6 supports `string.prototype.includes`[1]
So moral of the story: Before ranting and using something, bother to look if it is still a problem. They might have fixed it.
[1] https://developer.mozilla.org/en/...4 -
Argh
Help
If you know, a specific string is always going to be the same, and theres no way any other value could be passed to this statement. Is it still ok to use string.substring(0, string.IndexOf(&$&$))?
I feel dirty every time....1