Saturday, June 24, 2023

Get Value Multi Combo Box Vanilla Js


<select multiple id="test" style="width: 100px;">

    <option value="1">1</option>

    <option value="2">2</option>

    <option value="3">3</option>

</select>



<script>

const multi = document.getElementById("test");

multi.addEventListener("change",(e)=>{

    const arr = [];

    for(var i = 0; i < e.target.selectedOptions.length; i++){

            console.log(e.target.selectedOptions[i].value);

    }

});

</script> 

Saturday, June 3, 2023

Count Duplicate String Javascript

 const arr = ["a", "b", "c", "d", "d", "e", "a", "b", "c", "f", "g", "h", "h", "h", "e", "a"];

const counts = arr.reduce((acc, value) => ({
   ...acc,
   [value]: (acc[value] || 0) + 1
}), {});

console.log(counts);

Set Cookie dan Remove Cookie dengan php vanilla.js

< html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport...