I'm looking for the most efficient way to rename (append-1, -2 etc.) a variable, if it already exists in a string.
So I'm keeping an array"
dupeCheck = [];
And as soon as I see that a variable:
var UID;
Is already in my dupeCheck array, I want to immediately append the value of UID with -1,
Also, I need to prevent a third duplicate becoming string-1-1, but rather string-2..
I saw this: Appending the count to duplicates in a javascript string array before, but It's nog exactly what I want...
Any smart ideas? I prefer jQuery..
/Edit:
For example:
var dupeUIDCheck = [];
$.each(data[IDS].UIDs[keys], function(keys, val)
{
var currString = val;
switch (key)
{
case "UID":
UID = unquote(currString);
//TODO:
//Detect if multiple UIDs are loaded from a single source, and
//rename them:
dupeUIDCheck.push(UID); //Push current ID onto existing array
//Check if ID exists
?
//If exists rename value of currString, save it in currString
newName = currSting;
break;
case "otherstuff":
//Other vars to parse
break;
}
So when we get out of the "UID" case, I want to make sure it has a unique value
dupeCheck's values? I don't know what you're trying to do.