str[i] = "x"
Так можно только читать.function reverse(str) {
var i, len = str.length, result = "";
for (i = len - 1; i >= 0; i--) result += str[i];
return result;
}
const select = document.querySelector('здесь селектор вашего select\'а');
const addValToText = option => addText(option, getVal(option));
const getVal = option => option.value;
// или
const getVal = option => option.getAttribute('value');
// или
const getVal = option => option.attributes.value.value;
const addText = (option, text) => option.text += text;
// или
const addText = (option, text) => option.textContent = option.textContent.concat(text);
// или
const addText = (option, text) => option.innerText = `${option.innerText}${text}`;
// или
const addText = (option, text) => option.append(text);
// или
const addText = (option, text) => option.insertAdjacentText('beforeend', text);
// или
const addText = (option, text) => option.appendChild(document.createTextNode(text));
// или
const addText = (option, text) => option.insertBefore(new Text(text), null);
Array.prototype.forEach.call(select, addValToText);
// или
select.querySelectorAll('option').forEach(addValToText);
// или
for (const n of select.options) {
addValToText(n);
}
// или
for (let i = 0; i < select.children.length; i++) {
addValToText(select.children[i]);
}
4.5.1. The a element
Content model:
Transparent, but there must be no interactive content or a element descendants.
Interactive content is content that is specifically intended for user interaction.
a (if the href attribute is present), audio (if the controls attribute is present), button, details embed, iframe, img (if the usemap attribute is present), input (if the type attribute is not in the Hidden state), label, select, textarea, video (if the controls attribute is present).
The tabindex attribute can also make any element into interactive content.
indexOf()
this.children
, а хочется.[]
и его метод indexOf
call()
(подробнее)indexOf
в качестве this
(где искать) — this.children
,event.target
event.target
среди this.children
-1
, если не нашлось. const langTests = {
'en': textEn,
'ru': textRu,
};
const getText = (lang) => {
const tests = langTests[lang];
return tests[Math.floor(Math.random() * tests.length)];
}
let language = 'en';
getText(language) // 'test2'
gl_FragColor = vec4(color, 0.4 * start);
gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
array.reduce((accumulator, value, index) => {
if (!(accumulator[index % 2] instanceof Array)) {
accumulator[index % 2] = [];
}
accumulator[index % 2].push(value);
return accumulator;
}, []);
array.reduce((accumulator, value, index) => {
accumulator[index % 2].push(value);
return accumulator;
}, [[], []]);
array.reduce((accumulator, value, index) => (accumulator[index % 2].push(value), accumulator), [[], []]);
array.reduce((a, v, i) => (a[i % 2].push(v), a), [[], []]);
const countOff = (array, count) => array.reduce((accumulator, value, index) => {
accumulator[index % count].push(value);
return accumulator;
}, Array.from({ length: count }, () => []));
countOff([1, 2, 3, 4, 5, 6], 2); // [[1, 3, 5], [2, 4, 6]]
countOff([1, 2, 3, 4, 5, 6], 3); // [[1, 4], [2, 5], [3, 6]]
const countUniqueChars = str =>
new Set(str).size;
const countUniqueChars = str => [...str]
.reduce((acc, n) => (acc.includes(n) || acc.push(n), acc), [])
.length;
const countUniqueChars = str => Array
.from(str)
.reduce((acc, n, i, a) => acc + (i === a.indexOf(n)), 0);
const countUniqueChars = str => Object
.keys(Object.fromEntries([].map.call(str, n => [ n, 1 ])))
.length;
const countUniqueChars = str => str
.split('')
.sort()
.filter((n, i, a) => n !== a[i - 1])
.length;
const countUniqueChars = str =>
(str && str.match(/(.)(?!.*\1)/g)).length;