What do you want to save?
Add Code snippet
New code examples
-
Javascript 2022-03-19 13:15:08
jquery change query string parameter value
var currentUrl = 'http://www.example.com/hello.png?w=100&h=100&bg=white'; var url = new URL(currentUrl); url.searchParams.set("w", "200"); // setting your param var newUrl = url.href; console.log(newUrl); Add solution -
Other 2022-03-19 13:10:05
javascript loop an array
let array = ['Item 1', 'Item 2', 'Item 3']; // Here's 4 different ways for (let index = 0; index < array.length; index++) { console.log(array[index]); } for (let index in array) { console.log(array[index]); } for (let value of array) { console... Add solution -
Javascript 2022-03-19 08:00:26
javascript regex email
function validateEmail (emailAdress) { let regexEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; if (emailAdress.match(regexEmail)) { return true; } else { return false; } } let emailAdress = "[email protected]"; console.... Add solution -
Other 2022-03-19 02:55:50
Check first character of string in array and compare to another array
a = ['ghis', 'rs', 'ea','eat' ,'nentence'] let word = '' function check(arr){ let color = ['green'] for(let i = 0; i < arr.length;i++){ word += arr[i][0] } for(let j = 0;j < color.length;j++){ if(word == color[j]){ return tru... Add solution -
Javascript 2022-03-18 07:30:11
reverse keys and values in object javascript
//The concise way by using ES6 syntax like this. const obj = {A : 1, B : 2, C : 3, D : 4} function objectFlip(obj) { return Object.entries(obj).reduce((acc, [key, value]) => (acc[value] = key, acc), {}) } console.log('input: ',obj); console.lo... Add solution -
Javascript 2022-03-18 07:20:11
Redux
Redux is a state management library 1 Create Initial State 2 Define Action Types 3 Define Action Creators 4 Create Reducers 5 Change the initial State 6 Pass the parameters to the Creator function and the reducers Code // Initial State const initialStat... Add solution -
Javascript 2022-03-18 06:45:12
javascript how to pass an action back in a function
// Create a callback in the probs, in this case we call it 'callback' function newCallback(callback) { callback('This can be any value you want to return') } // Do something with callback (in this case, we console log it) function actionAferCallback (c... Add solution