Vue 3 array filtering does not result in a new array being generated

I'm a bit confused about the behavior in Vue 3 when filtering a reactive array to create a new array and then modifying the new array, why does it update the original one? Shouldn't the filter operation generate a completely separate array with no connection to the original one? I'd appreciate any clarification on this. Here is a link to an example on CodeSandbox showcasing this issue: https://codesandbox.io/s/vue-3-glziy?file=/src/components/HelloWorld.vue

Thank you for your help.

Answer №1

Actually, I just had a light bulb moment and solved the problem myself. Turns out, Filter creates a shallow copy which retains a reference to the original object. That's news to me!

Learn more about shallow copies here

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

What is the best method to assign the value of a useState variable to a specific field in an array of objects for inserting data in

**I have a billing form that includes product details for the admin to fill out. One field, labeled "BillID", should automatically populate with a default value of 'Bill ID + 1' through a variable. **Below is the code: const [BillIdFetch, setB ...

Having trouble with uploading an image in Laravel using a modal?

For my laravel inventory system, I am facing an issue with uploading images for products. The old code I used for image upload is not working in my current project where I am utilizing a modal and ajax request to save inputs in the database. Can anyone pro ...

Iterating through each object in the JSON file to showcase details about planes

Question How do I set up a functional example of these airplanes? Background I seem to have the initial part working, indicating that my loop may be causing issues. While I can extract the number of planes, I'm facing difficulties displaying all th ...

Exploring the use of the layout property within the <script setup> tag

Is there a way to utilize the layout property from InertiaJS for Vue 3 within the <script setup> tag? Specifically, I am looking for an alternative to the following code snippet: <script> import from "../Shared/Layout"; export defaul ...

Is there a way to prevent an HTML5 video from pausing or stopping when scrolling?

At the top of my page, there's a HTML5 video banner with the autoplay and loop attributes. However, when I start scrolling down, the video stops and doesn't resume when I scroll back up. I want the video to keep playing regardless of the user&apo ...

Issue encountered when attempting to establish a connection to mongoDB using Node.js: "The initial parameter supplied to mongoose.connect() must be a string."

When I tried to run app.js, I encountered the following error: Error message: 'The uri parameter to openUri() must be a string, got "undefined". Make sure the first parameter to mongoose.connect() or mongoose.createConnection() is a string.' Er ...

Changing a C# Datetime type to a Date using javascript in an ASP.NET MVC Razor web application

Having trouble converting dates in JavaScript? Check out this code snippet: $(document).ready(function () { var date = new Date(); var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); ...

React is unable to access and retrieve data from a web API

Currently, I have a controller set up in web-api for my project. I am using React v18.2.0 and NextJS v13.3.0 to work with this setup: public List<ReturnDat> Get() { List<ReturnDat> lst = new List<ReturnDat>(); lst.Add(new ReturnD ...

What is the best method for obtaining user data when additional custom data is stored in Cloud Firestore?

Storing the user's information such as email, name, age, phone number, and uid is essential. In the user.model.ts file: export interface User { uid: string, name: string, email: string, phoneNumber: string, age: string } In auth. ...

Having trouble connecting to device sensors with Nuxt.js

I am attempting to implement Gyroscope event listening in a nuxtjs application. After researching the sensor API, I attempted to integrate it as shown below: mounted () { this.gyroscope = new Gyroscope({ frequency: 60 }) this.gyroscope.addEventLi ...

What is the best way to assign specific codes to separate pages using a single JS file?

I am currently working on a project that involves an authentication JavaScript which is responsible for managing user sign-ins and registrations. However, there are certain lines of code within this script that impact different pages in various ways. I n ...

What methods can be used to dynamically pan the entire picture in a programmatic way?

I have a massive div measuring 11500x11500 pixels that contains 400 images, causing it to overflow the viewport. My goal is to programmatically pan across the entire div. I'm aiming to create an animation that pans the entire div from top to bottom, ...

Retrieve a form (for verification purposes) from a separate AngularJS component

I'm facing an issue with accessing a form from one component to another in my project. One component contains a form, and the other has navigation buttons that, when clicked, should validate the form before moving on to the next step. However, I alway ...

The function that triggers an image slide event in Bootstrap 4 carousel

Currently, I have implemented a bootstrap 4 carousel with 11 slides that are functioning as intended. I now have another div (#div-info) where I would like to display specific text and images based on the active carousel slide. For example, when slide 2 is ...

Is it possible to safeguard undisclosed data in browser console?

Can JavaScript be employed to prevent users from editing hidden fields through the browser console? ...

Tips for utilizing 'toHaveClass' to find a partial match in Jest?

When I assign the class success to an element, React-Mui appends additional text to it in the DOM, such as mui-AbcXYZ-success. This causes my test using the code snippet below to fail: expect( getByTestId('thirdCheck')).toHaveClass("success ...

Display localization keys in Vue using i18n

Are there any ways to display the keys using localization? I came across a solution in the documentation which suggests creating decision maps for fallbackLocale. My approach was to define a decision for default -> en and a decision for 'not-a-lan ...

The modal popup will appear in the center of the screen when the scrollbar is positioned at the top

I have a modal popup that is not consistently displayed in the center of the screen, regardless of the scrollbar position. I always want it to render at the center so the user doesn't need to scroll to see it. Below is the code I am currently using: ...

The RGB values of a dynamically loaded image being drawn to a canvas in JavaScript are slightly off

After hosting some .PNG images on my NGINX webserver, I noticed a discrepancy in the RGB values when loading and drawing them on a canvas using context.drawImage(img, 0, 0); and retrieving the image data using context.getImageData(x, y, 1, 1).data. Interes ...

Condensing an Array of Objects into a solitary result

Hey there, I'm currently exploring the most efficient method to accomplish a task. The data I am dealing with looks something like this: [ { name: 'email.delivered', programme: 'Email One', timestamp: 2022-03-24T18: ...