how to make a toggle between two strings in js code example
Example: how to make a toggle between two strings in js
if (value == 'string0') {
value = 'string1';
} else {
value = 'string0';
}
value = (value == "string0") ? 'string1' : 'string0';
let strings = ['string0', 'string1', 'string2'];
if (strings.indexOf(value) < strings.length - 1) {
value = strings[strings.indexOf(value) + 1];
} else {
value = strings[0];
}
value = (strings.indexOf(value) < strings.length - 1) ? strings[strings.indexOf(value) + 1] : strings[0];