How does one update the array based on symbols? Like
data = []
string = "Hello"
if( !data.include? string )
count += 1
data.insert(-1, {
label: string,
value: count,
})
else
#logic to change count value if string is encountered again
end
I was thinking of finding the index where the string lies and then delete that to insert another updated values at that index. Is this the right approach?
Just use
findto get the match, provided its the only one in the array. You can useselectto get multiple matches. After that just update the countAs your example is taken out of context and contains errors, I've taken a liberty to make a more complete example.