Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Finding last ( in the string
Message
 
 
To
All
General information
Forum:
Javascript
Category:
Coding, syntax & commands
Title:
Finding last ( in the string
Miscellaneous
Thread ID:
01652707
Message ID:
01652707
Views:
60
UPDATE.

Apparently a similar code is used in several places.

So, I have a question - if I want to return two strings as a result, would this solution work
function splitName (fullName)
{
  var item = {description : partOne, nickname : partTwo };

  return item;
}
and use it as
var splittedName  = splitName ("Some String (here)")

var firsPart = splittedName.description;
var secondPart = splittedName.nickname;
Hi everybody,

My colleague wrote the following code
 for (var i = 0; i < data.departments[0].items.length; i++) {
                                    var temp = data.departments[0].items[i].title.split("(");
                                    var description = temp[0];
                                    var nickname = temp[1].split(")")[0];

                                    allDepartments.push({
                                        "id": data.departments[0].items[i].intKeys[0],
                                        "descrip": description,
                                        "nickname": nickname,
                                        "preventDefault": true,
                                        "hash": data.departments[0].items[i].keys[0],
                                        "hidden": data.departments[0].items[i].hidden
                                    });
                                }
which is failing when description itself has () in it.

So, how can I adjust the var description and var nickname lines above to get information before the very last ( in the string. E.g. nickname is in the () at the end of the string and description may include more () inside. I guess we should not use split function, but may be reverse and indexof?

Thanks in advance.

UPDATE. Found this

https://www.w3schools.com/jsref/jsref_lastindexof.asp

Looks like I may use that.
If it's not broken, fix it until it is.


My Blog
Next
Reply
Map
View

Click here to load this message in the networking platform