How to get an array of 10 next Mondays in javascript

Here is my code but this array returns only the same elements, i am trying to create an array which contains 10 elements as the next mondays anyone know please help me

my code:

function getNextDayOfTheWeek(dayName, excludeToday = true, refDate = new Date()) {
    const dayOfWeek = ["sun","mon","tue","wed","thu","fri","sat"]
                      .indexOf(dayName.slice(0,3).toLowerCase());
    if (dayOfWeek < 0) return;
    refDate.setHours(0,0,0,0);
    refDate.setDate(refDate.getDate() + +!!excludeToday + 
                    (dayOfWeek + 7 - refDate.getDay() - +!!excludeToday) % 7);
    return refDate;
}
let arr=[]
for(let i=0;i<10;i++){
    arr.push(arr[i]=getNextDayOfTheWeek("Monday",false))
}

console.log(arr)

How to sort an Array by the arrays within it?

I have this array

Array(5)
0: {message: Array(5), objectId: 'DaGoat'}
1: {message: Array(1), objectId: 'yo'}
2: {message: Array(4), objectId: 'Big C'}
3: {message: Array(4), objectId: 'me'}
4: {message: Array(1), objectId: 'hmmmmmm'}

that I am trying to arrange according to the arrays contained in each line for example have 0-4 be in descending order due by a column inside the message array. Could someone guide me in the direction in solving this through JS?

Modal content showing up but not as a pop-up

I’m trying to display a modal but for some reason, the content inside the modal shows up on the page permanently there but it’s not a pop-up.

Here is the code for this component:

import React, {useState} from "react";
import {Button, Modal, ModalHeader, ModalBody, ModalFooter} from 'reactstrap';
import Checklist from "./ChecklistView";

const Checklists = () => {
    const [modal, setModal] = useState(false);
    const toggle = () => setModal(!modal);
    return (
        <div>
            <div className = "header">
                <h1>Let's get productive.</h1>
            </div>
            <div className = "checklist-view">
            <Button onClick = {() => setModal(true) }>Create Checklist</Button>
            </div>
            <CreateChecklist toggle = {toggle} modal = {modal}/>
        </div>
    )
}

const CreateChecklist = (modal, toggle) =>{
    return (
        <Modal isOpen={modal} toggle={toggle}>
            <ModalHeader toggle={toggle}>Create Checklist</ModalHeader>
            <ModalBody>
               <Checklist />
            </ModalBody>
            <ModalFooter>
                <Button onClick={toggle}>Confirm</Button>
                <Button onClick={toggle}>Cancel</Button>
            </ModalFooter>
        </Modal>
    )
}


export default Checklists

Access localStorage of chrome extension in background script

I need to access the localStorage of a chrome extension in background.js to get values which have been set by the extension popup itself. The key-value pair is existing, I checked that by inspecting the extension popup.

However, reading from the localStorage by using the code below leads to an undefined result.

background.js:

chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        chrome.storage.local.get(['allowedSites'], function(result) {
            console.log('allowedSites: ', result.allowedSites);
        });
    }
);

The storage permission is set in v3 manifest. Any ideas what’s wrong with this code?

Any problem using localStorage instead of $page.params.id in Sveltekit?

In sveltekit, any problem using localStorage for passing along a post id from a list to a detail or edit page instead of using $page.params.id?

Instead of having a page “edit/[id].svelte” it will just be “edit.svelte”.

Pros and cons? Any risk of it being slow to setItem before getItem in edit.svelte compared to using $page.params.id?

Should be easy to understand without showing any code. I know it has been somewhat answered e g for react and perhaps the answer is the same but I only know svelte.

Activer une balise input au clic d’un image ‘modifier’

Bonjour,

Je suis en train de coder un site dans lequel l’administrateur a une page dashboard avec la liste des utiilisateurs. J’aimerai permettre à l’admin de changer le rôle d’un utilisateur dans une ligne.
Voici le code:

<table>
<caption> Liste des utilisateurs </caption>
<tr class="title">
    <th>Date de création</th>
    <th>Prénom</th>
    <th>Nom d'utilisateur</th>
    <th>Mail</th>
    <th>Rôle</th>
    <th>Id</th>
</tr>

<tr>
    <td>0000-00-00 00:00:00</td>
    <td></td>
    <td>username</td>
    <td>*****@mail.fr</td>
    <td>admin</td>
    <td>22</td>
    <img class="information_modify" src="chemin" alt="img_modifier"> 
</tr> 
 
<tr>
    <td>2022-05-08 09:29:53</td>
    <td></td>
    <td>username</td>
    <td>****@mail.fr</td>
    <td>user</td>
    <td>23</td>
    <img class="information_modify" src="chemin" alt="img_modifier"> 
</tr>
</table>

J’ai deux problèmes:

  1. je ne sais pas comment faire pour changer une balise td en input, surement avec du JS…

  2. Quand bien meme j’arrivais à le faire, comment faire pour que ça change la balise td uniquement de la ligne. En sachant que j’utilise une boucle foreach en php pour générer ce code.

J’en appelle donc à vous. Merci d’avance pour vos réponses 😉

useEffect not warking but why?

useEffect(() => {
    const email = user.email
    const url = `https://secret-hamlet-95232.herokuapp.com/productOrder?email=${email}`
        fetch(url)
        .then(res => res.json())
        .then(data => setMyorder(data))
}, [])

I need remedy of this error: BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer

Server code node.js, express app

app.put('/items/:id', async(req, res) => {
  const id = req.params.id;
  console.log(id, 'came from id=> app.put');
  const qty = req.body;
  console.log(qty, 'came from quantity=> app.put');
  const filter = {
    _id: ObjectId(id)
  };
  console.log(filter, 'came from filter=> app.put')
  const options = {
    upsert: true
  };
  console.log(options, 'came from options=> app.put')
  const updatedDoc = {
    $set: {
      qty: qty,
    }

  }
  console.log(updatedDoc, 'came from updateddoc=> app.put')
  const result = await userItems.updateOne(filter, updatedDoc, options);
  console.log(result, 'came from result=> app.put')
  res.send(result);
})

Client side code

const handleQuantity = event => {
  event.preventDefault();
  const qty = event.target.qty.value;
  console.log(qty);
  const url = `http://localhost:4000/items/${id}`
  fetch(url, {
      method: 'PUT',
      body: JSON.stringify({
        qty: qty
      }),
      headers: {
        'Content-type': 'application/json; charset=UTF-8',
      },
    })
    .then((response) => response.json())
    .then(data => {
      console.log(data);

    });
}

The error I’m getting:

port 4000
[object Object] came from id=> app.put
{ qty: '5' } came from quantity=> app.put
D:web developmentwarehouse-management-server-side-pippal5536node_modulesbsonliberror.js:41
        var _this = _super.call(this, message) || this;
                           ^

BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer  
    at new BSONTypeError (D:web developmentwarehouse-management-server-side-pippal5536node_modulesbsonliberror.js:41:28)
    at new ObjectId (D:web developmentwarehouse-management-server-side-pippal5536node_modulesbsonlibobjectid.js:66:23)
    at ObjectId (D:web developmentwarehouse-management-server-side-pippal5536node_modulesbsonlibobjectid.js:26:20)
    at D:web developmentwarehouse-management-server-side-pippal5536index.js:73:27
    at Layer.handle [as handle_request] (D:web developmentwarehouse-management-server-side-pippal5536node_modulesexpresslibrouterlayer.js:95:5)
    at next (D:web developmentwarehouse-management-server-side-pippal5536node_modulesexpresslibrouterroute.js:144:13)
    at Route.dispatch (D:web developmentwarehouse-management-server-side-pippal5536node_modulesexpresslibrouterroute.js:114:3)
    at Layer.handle [as handle_request] (D:web developmentwarehouse-management-server-side-pippal5536node_modulesexpresslibrouterlayer.js:95:5)
    at D:web developmentwarehouse-management-server-side-pippal5536node_modulesexpresslibrouterindex.js:284:15
    at param (D:web developmentwarehouse-management-server-side-pippal5536node_modulesexpresslibrouterindex.js:365:14)
[nodemon] app crashed - waiting for file changes before starting...

JSON data not showing without live server in vscode when i start live server it shows data but when i copy index path to browser i doesn’t show data? [duplicate]

With Live server
Without Live Server

JS code:

$(document).ready(function () {

    // FETCHING DATA FROM JSON FILE
    $.getJSON("team.json", function (data) {
       let datainfo=JSON.stringify(data);
       let cinfo=JSON.parse(datainfo);

        for(let i in cinfo){   
            $(".card img")[i].src=cinfo[i].url;    
            $(".card img")[i].alt=cinfo[i].name;       
            $(".card-title")[i].innerHTML=cinfo[i].name;
            $(".card-title-1")[i].innerHTML=cinfo[i].job;
            $(".card-text")[i].innerHTML=cinfo[i].description;
        }
    });
});

JSON data:
[
{
“url”:”image/team-1.jpg”,
“name”: “John Doe”,
“job”:”Front End Developer”,
“description”: “Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s.”
},
{
“url”:”image/team-2.jpg”,
“name”: “Sara William”,
“job”:”Content Writer”,
“description”: “Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry.”
},
{
“url”:”image/team-3.jpg”,
“name”: “David Waht”,
“job”:”Digital Marketing Expert”,
“description”: “Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s.”
}
]

How to replace span tags with its own class name inside paragraph

I want to replace all <span></span> tags with their own class name inside the dynamic paragraph.

Example:

My paragraph is: "Welcome <span class="emo 1f4a9"></span> to our home <span class="emo 1f47b"></span>"

And I want the result: "Welcome 1f4a9 to our home 1f47b"

So I tried many ways but can’t be got the class name of span. The paragraph comes from an ajax request as a text format for my public comment section and I will show it also as a push notification.

I tried

spantoemo('Welcome <span class="emo 1f4a9"></span> to our home <span class="emo 1f47b"></span>');
function spantoemo(MSG){
var element = $(MSG);   
element.find("span").each(function(index) {
        var A = $(this).attr('class');
        var B = A.replace("emo ", ""); 
        //var JAVACODE = toUTF16(parseInt( A, 16 )); var FINAL =  html.replace(/<span class="+A+"></span>/g, JAVACODE);
        var FINAL =  html.replace(/<span class="+A+"></span>/g, B);
});
var newString = element.html(); //get back new string
alert(newString);
}

And fiddle

Setting request Header in Angular post request method globally

I have the following method in an angular service which is working properly

 getMyRequests( userId: string){
    const headers = new HttpHeaders().set('Authorization', `Bearer ${localStorage.getItem(CONSTS.MIDDLEWARE_TOKEN)}`);
    return this.http.post<any>(this.MIDDLEWARE_MY_REQUESTS,{ "userId": userId  }, { headers , params: null })
  }

However the headers part is set locally in the method, and since it used multiple times in differnt methods within the same service I would like to set it in the service globally
I tried the following but it doest work

export class MyService {
  
      headers = new HttpHeaders().set('Authorization', `Bearer ${localStorage.getItem(CONSTS.MIDDLEWARE_TOKEN)}`);
     getMyRequests( userId: string){
        return this.http.post<any>(this.MIDDLEWARE_MY_REQUESTS,{ "userId": userId  }, { this.headers , params: null })
      }

I would like to know what is the correct solution for this?

How to get rid of the horizontal gaps between cells in CSS grid for smaller screens?

Problem faced: The CSS grid applied in my app has horizontal gaps between cells. These horizontal gaps appear when the screen is toggled in mobile mode as seen here CodeSandbox. This problem is prominent in smaller screens (mobile) and when the cells have the same background colour as shown in the CodeSandbox. To see the problem in the CodeSandbox, please select “Toggle Responsive View” (2nd icon from right of the url bar under “Browser” tab).

What I require: If the code above can be modified to eliminate these gaps or a code snippet that solves the problem can be shown, that would be greatly appreciated.

React Component Library using Webpack

Hello is it possible to make a react component library using script tag and npm in the same code base

example I have a next js app then I will import the component in script tag

    <script
         type="module"
         src="https://cdn.jsdelivr.net/gh/@me/bundle.js"
      ></script>

and also I can import the component using

import Mycomponent from '@me/librayname'

Is this possible currently I implement it using different code base/repository which is confusing im using tsdx for npm library and webpack for scriptag. If anyone can guide me here is much appreciated. Thank you