at (index)
Gets the element at the specified index within the WebUI object. A negative index will count back from the end of the array.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { const elements = webui("#button1, #button2, #button3, #button4"); let element = elements.at(2); });
concat (array1, array2, ...)
Merges one or more array like objects into a new array.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { const obj1 = webui("#button1, #button2"); const obj2 = webui("#button3, #button4"); let elems = obj1.elements().concat(obj2.elements()); });
every (callback)
Tests whether each element in an array meets the conditions specified by the provided callback function.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { const elems = webui("#button1, #button2, #button3, #button4"); const isButton = (currentValue) => ui(currentValue).is("button"); const result = elems.every(isButton); });
filter (callback)
Creates a new array containing the elements of an original array that meet the conditions specified by the provided callback function.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-success" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-success" id="button4">Button 4</button>
webui.ready( () => { const elems = webui("#button1, #button2, #button3, #button4"); let filteredArray = elems.filter((button) => ui(button).hasClass("button-success")); });
forEach (callback)
Calls the callback function for each element in an array.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { const elems = webui("#button1, #button2, #button3, #button4"); elems.forEach((element) => { console.log(element); }); });
includes (value)
Searches an array for the presence of the specified value.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { const elems = webui("#button1, #button2, #button3, #button4"); const elem = webui("#button3"); const result = elems.includes(elem[0]); });
indexOf (value)
Returns the index of the specified value within an array.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { const elems = webui("#button1, #button2, #button3, #button4"); const elem = webui("#button3"); const result = elems.indexOf(elem[0]); });
join (separator)
Returns a concatenated string separated by commas, or separated by a specified separator.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { const elems = webui("#button1, #button2, #button3, #button4"); const mapped = elems.map((x) => ui(x).text()); const str = mapped.join(); });
map (function)
Returns a new array containg all elements of the original array, but transformed by specified function.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { const elems = webui("#button1, #button2, #button3, #button4"); const arr = elems.map((x) => ui(x).text()); });
pop ()
Removes the last element from an array and returns it.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { const elems = webui("#button1, #button2, #button3, #button4"); const elem = elems.pop(); });
push (object, object, ...)
Adds new elements to the end of an array and returns the new length.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { const elems = webui("#button1, #button2, #button3"); const newElem = ui("#button4"); const length = elems.push(newElem); });
reduce (callback)
Reduces the values of elements in an array to a single value by executing a callback function used to accumulate a running result.
<input type="text" value="22.5" id="txt1" /> <input type="text" value="17.1" id="txt2" /> <input type="text" value="6.9" id="txt3" /> <input type="text" value="12.7" id="txt4" />
webui.ready( () => { const elems = webui("#txt1, #txt2, #txt3, #txt4"); const initialValue = 0; const total = elems.reduce( (accumulator, current) => accumulator + parseFloat(current.value), initialValue, ); });
reduceRight (callback)
Reduces the values of elements in an array to a single value by executing a callback function used to accumulate a running result. ReduceRight works from the end of an array to the beginning.
<input type="text" value="22.5" id="txt1" /> <input type="text" value="17.1" id="txt2" /> <input type="text" value="6.9" id="txt3" /> <input type="text" value="12.7" id="txt4" />
webui.ready( () => { const elems = webui("#txt1, #txt2, #txt3, #txt4"); const initialValue = 0; const total = elems.reduceRight( (accumulator, current) => accumulator + parseFloat(current.value), initialValue, ); });
reverse ()
Reverses the order of all elements in an array and returns the it.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { let elems = webui("#button1, #button2, #button3, #button4"); const arr = elems.reverse(); });
shift ()
Removes the first element in an array and returns the it.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { let elems = webui("#button1, #button2, #button3, #button4"); const firstItem = elems.shift(); });
slice (start, end)
Returns a copy of all or part of an array, depending on the start and end index. If no end index is specified then an array from start to the end of the array is returned. If no start index is specified a copy of the original array is returned.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { const elems = webui("#button1, #button2, #button3, #button4"); const arr = elems.slice(2); });
some (callback)
Returns true or false, depending on whether at least one element of an array meets the condition specified by the callback function.
<input type="text" value="22.5" id="txt1" /> <input type="text" value="17.1" id="txt2" /> <input type="text" value="6.9" id="txt3" /> <input type="text" value="12.7" id="txt4" />
webui.ready( () => { const elems = webui("#txt1, #txt2, #txt3, #txt4"); const result = elems.some((x) => parseFloat(x.value) > 30); });
sort (compare)
Sorts an array according to the specified compare function, or sorts in acsending order using a string comparison if no compare function is provided.
<input type="text" value="22.5" id="txt1" /> <input type="text" value="17.1" id="txt2" /> <input type="text" value="6.9" id="txt3" /> <input type="text" value="12.7" id="txt4" />
webui.ready( () => { const elems = webui("#txt1, #txt2, #txt3, #txt4"); function compareNumbers(a, b) { return a.value - b.value; } const arr = elems.sort(compareNumbers); });
splice (start, deleteCount, item, item, ...)
Inserts elements into an array at the start index and optionally deletes elements of an array from the start index, then returns an array containing the deleted elements.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { let elems = webui("#button1, #button4"); const arr = elems.splice(1, 0, ui("#button2").element(), ui("#button3").element()); });
toReversed ()
Creates a new array with all elements in reverse order. The original array is not changed.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { let elems = webui("#button1, #button2, #button3, #button4"); const arr = elems.toReversed(); });
toSorted (compare)
Creates a new array and sorts it according to the specified compare function, or sorts in acsending order using a string comparison if no compare function is provided. The original array is not changed.
<input type="text" value="22.5" id="txt1" /> <input type="text" value="17.1" id="txt2" /> <input type="text" value="6.9" id="txt3" /> <input type="text" value="12.7" id="txt4" />
webui.ready( () => { const elems = webui("#txt1, #txt2, #txt3, #txt4"); function compareNumbers(a, b) { return a.value - b.value; } const arr = elems.toSorted(compareNumbers); });
toSpliced (start, deleteCount, item, item, ...)
Creates a new array, inserts elements into it at the start index and optionally deletes elements of an array from the start index, then returns the array modified array. The original array is not changed.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { let elems = webui("#button1, #button4"); const arr = elems.toSpliced(1, 0, ui("#button2").element(), ui("#button3").element()); });
unshift (elem1, elem2, ...)
Adds elements to the beginning of an array and returns the length of the expanded array.
<button class="button-sm button-info" id="button1">Button 1</button> <button class="button-sm button-info" id="button2">Button 2</button> <button class="button-sm button-info" id="button3">Button 3</button> <button class="button-sm button-info" id="button4">Button 4</button>
webui.ready( () => { let elems = webui("#button3, #button4"); const length = elems.unshift(ui("#button1").element(), ui("#button2").element()); });