js

update object value in an array in javascript

  const storage= [ { id:1, name:“kahnu”, email:“kahnu@gmail.com”, age:21, phone:1234567890 }, { id:2, name:“kahnu2”, email:“kahnu2@gmail.com”, age:22, phone:1234567890 }, { id:3, name:“kahnu3”, email:“kahnu3@gmail.com”, age:23, phone:1234567890 } ] const objIndex = storageData.findIndex((obj => obj.id == ‘1’)); storageData[objIndex].name = ‘new name’; storageData[objIndex].email = ‘new email’; storageData[objIndex].age = ‘new age’; console.log(“After update: “, storageData[objIndex])

Copy to clipboard in jquery

 function copyToClipboard(elementId) { var copyTextarea = document.getElementById(elementId); console.log(copyTextarea); copyTextarea.select(); document.execCommand(“copy”); jQuery(“.copy”).html(“Copied”); if (jQuery(‘.tcopy’).length) { jQuery(‘#’ + elementId.slice(1)).html(“Copied”); } jQuery(“#liveToast”).toast(“show”); }

get date and time from timestamp in js

  function getDateTime(MatchTimeStamp){     var date = new Date(MatchTimeStamp); var Hours = date.getHours() >12 ? date.getHours()-12 : date.getHours(); var ampm = date.getHours() >= 12 ? ‘pm’ : ‘am’; var fullDate = `${date.getDate()}–${date.getMonth()+1}–${ date.getFullYear()}`; var fullTime = `${Hours}:${date.getMinutes()} ${ampm}`; return {‘date’: fullDate , ‘time’ : fullTime} }

using same component for different route path in react-router v6

Using different key for each route should force components to rebuild: import React, { Component } from ‘react’;import Navbar from ‘./Components/Navbar’;import News from ‘./Components/News’;import Test from ‘./Components/Test’;import NoMatch from ‘./Components/NoMatch’;import { BrowserRouter , Route, Routes } from ‘react-router-dom’export default class App extends Component { render() { return <div> <BrowserRouter> < Navbar /> <Routes> <Route path=”/” element={<News pageSize={8} …

using same component for different route path in react-router v6 Read More »