what is the way to send arguments with the rest parameter in javascript?

Here is the function call I need help with:

await this.myFunction({'fields.page': page, ...filters});

This is my function code:

async myFunction({state, commit}, filters) {

const {items} = await fetchData({content_type: state.contentType, ...filters});

const data = items.map((item) => {
  return {
    id: item.systemId,
    ...item.fields,
  };
});

commit('setData', data);

return data;}

I am looking to pass two more parameters along with the rest operator. Any suggestions on how I can achieve that?

Answer №1

To start, instantiate an object with 2 specific keys and then employ the spread operator for filtering purposes, as demonstrated below:

const filteredData = await this.getData({'criteria.page': page, key1: 'value1', key2: 'value2', ...filters });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The callback response in Node's exec function is behaving incorrectly

When I have a route handling a URL post request, I am running an exec on a bash command. Strangely, the console.log is working fine indicating that the bash command ends and the callback is triggered. However, for some reason, the response fails to send ...

Every time the page is refreshed, the value stored in React localStorage gets

After adding a new item to the list, the local storage gets updated. However, upon page refresh, I noticed that the key remains but the value is reset to an empty array. import { useState, useEffect } from 'react'; function App() { const [data ...

Keep Array up-to-date as new elements appear on the webpage

Currently, I am developing a Chrome extension that requires me to retrieve the total number of books available in a library. The current code snippet is functioning correctly, but the issue arises when the page loads only half of the books initially and ...

Switch the dropdown selection depending on the checkbox status

I'm currently facing a bit of confusion with my project. I am constrained by an existing framework and need to come up with a workaround. To simplify, I am tasked with populating a dropdown list based on the selected checkboxes. I have managed to get ...

The malfunction of return statement in JavaScript when using Angular

I'm having an issue with my Angular code not working when it's written in a certain format. Here is the code: app.directive("strength", function() { return { require: "superhero", link: function(scope, element, attrs, superheroCtrl) { ...

Adding a loader to the specific button that has been clicked can be achieved by following these steps:

I am currently in the process of building an e-commerce platform website and I'm looking to implement a feature where users can add products to their cart with just a click of a button. However, before the product is added to the cart, I want to disp ...

Import React component dynamically by utilizing configuration entries

Within my React-redux-typescript project, I have multiple apps that are all part of a core application. I am looking to dynamically set up routing for these individual apps. The current structure of my routes is as follows: Routes.tsx import HomePageApp ...

The toggle feature in Bootstrap is stuck in the "on" position and refuses to "untoggle."

Currently, I am working on developing a basic website using Laravel and Vue.js. To ensure that the website is responsive, I integrated Bootstrap 4 into the project. For the most part, everything appears to be functioning correctly - the navbar collapses as ...

Adding a tooltip with a date format to a Highchart graph

Hey everyone, I'm currently working with a Highchart and I want to customize the tooltip value in a specific format. My categories and series are structured as follows: {"Categories":["2015-11-09","2015-11-08""2015-11-15"],"Series":[2,0,2]} Current ...

when the window is scrolled a certain amount, use jQuery to scroll back in the opposite direction

Using jQuery for Background Image Position: $(window).scroll(function() { var scroll = $(window).scrollTop(); if (scroll >= 50) { $(".class").addClass("bgposi"); // $(".top").addClass("fixd"); // $(".logo").addClass ...

Load images in an array using JavaScript and display them using the image source

I started by creating an array that contains several images function initialize(){ //adding 10 different images to the array imgArray[imageNum++] = new imageItem(imageDir + "img1.jpg"); imgArray[imageNum++] = new imageItem(imageDir + "img2.jpg"); imgArra ...

Seeking advice on modifying the background color within the code? (Designer delving into the coding realm)

Seeking guidance on changing the background color within this code. (designer navigating the coding realm) <script src="https://cdn.rawgit.com/mrdoob/three.js/fdefb19b/examples/js/renderers/CanvasRenderer.js"></script> <script src="https ...

Is it conceivable to generate fresh errors from an Ajax success event?

Whenever a server side error occurs in PHP, it is captured as a hash and then transmitted back to the client side using AJAX in the form of JSON. This way, the errors are effectively passed to the AJAX success event. ... catch ($e) { echo ( array("err ...

What could be causing the inconsistency in the persistence of my React useState hook's state?

I am currently working on developing an information panel in React that displays the most recent activity from an online community, specifically highlighting the latest individuals who have registered for the community. At the moment, I have a list of the ...

Discovering the worth in Meteor MongoDB

As someone who is new to web programming, I have been experimenting with Meteor and MongoDB lately. I have a form that sends data to MongoDB, and by using the query below, I was able to retrieve the most recent entry: database.findOne({}, {sort: {'t ...

Utilizing stored event names in a variable within VueJs

When working with VueJS, a child component has the ability to emit events like this: this.$emit('toggle-button') In the parent component, we can handle the emitted event in the following way: <my-component v-on:toggle-button="doSomething"&g ...

Verify if the item already exists in the Vue.js array

Here is the data I have: data: function() { return { conversations: [ ] } } I am retrieving my data from the response object using response.data.conversation Is there a method to verify if this.conve ...

Dragging a value from a chip in Vuetify and dropping it into an input does not function as expected

I am facing an issue with implementing drag-and-drop functionality using v-chip elements and a form. My goal is to enable users to drag any chip and drop it into the form so that the input field in the form captures the value of the dropped chip. Here is ...

Node.js not receiving data event in CORS ajax call

I am currently encountering an issue where the data event in my jQuery process is not being called when trying to receive JSON from an AJAX CORS call. Despite printing the JSON on the screen and verifying its presence, the data event remains uninvoked. Aft ...

Add a container element resembling a div inside a table without implementing the table layout

I am working with a table that is rendered by DataTable, and I have the requirement to dynamically append new elements inside the table like this: The dark grey area represents the new DOM elements that need to be inserted dynamically. The first row cont ...