Sending a property of an array object from Laravel to Vue

I need to access the name field in an array of objects that I am sending to my Vue component like this:

<article-form
    :edit-data-tags="{{ $article->tags }}"
></article-form>

The array looks like this:

[  0: { id:'1', name:'mytag' } ... ]

Once inside my component, I want to extract the name value so that I can store it and pass it along. How should I go about doing this?

The solution provided in this post seems promising, but when I attempt to implement it like so:

created: function () {
   for (let tag in this.editDataTags) {
      console.log(tag.name)
   }
}

I only get an undefined result.

Answer №1

If you are working with an array, consider using a different type of loop instead of a for...in loop. You could try a for...of loop:

for (let item of this.editDataItems) {
   console.log(item.name)
}

Alternatively, you can use the forEach method:

this.editDataItems.forEach(item => {
   console.log(item.name);
});

Another option is to use a traditional for loop:

for (let i=0; i < this.editDataItems.length; i++) {
   console.log(this.editDataItems[i].name)
}

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

Error: Unable to locate column 1054 - The specified column '0' does not exist in the field list within Laravel

I am encountering an issue when trying to insert data into the database using Excel format. I am utilizing the maatwebsite/excel package. UndanganController@store if ($request->hasFile('alamatExcel')) { //If using a courier $file = $ ...

Retrieving information from a JSON file using JavaScript

My code snippet looks like this: { "badge_sets":{ "1979-revolution_1":{ "versions":{ "1":{ "image_url":"https://static-cdn.jtvnw.net/badges/v1/7833bb6e-d20d-48ff-a58d-67f ...

Arrange SVGs using CSS in a grid with offsets

My current project involves creating a background using SVGs in React. I'm looking for an easy CSS method to arrange these icons in a grid, possibly with an offset for the second row. I also need the width of the icons to be dynamic so that they adj ...

Using JavaScript to display a confirmation dialog box with the content retrieved from a text input field

Can a confirm dialog box be used to show the user-entered value from a form's text box? For instance, if the user enters 100.00, I want the dialog box to say something like, "Confirm Amount. Press OK if $100.00 is accurate." ...

What is the best way to extract a single value from the given JSON dataset?

Is there a way to extract a single value from the JSON dataset provided below? ['X', 'Y', 'Z', 'W' ] Output: 1:X 2:Y 3:Z 4:W Your assistance with this matter would be greatly appreciated. ...

Implementing meta tags in React.js

I am attempting to incorporate dynamic meta-tags on each page of my website. However, despite my efforts, I cannot seem to locate the meta-tags in the page's source code. Do I need to make adjustments in public/index.html, considering that I am not ut ...

Having difficulty retrieving the value of a dynamically generated cell with document.getElementById

I have been facing an issue with adding rows to an HTML table that already contains 2 rows, using the following JavaScript code: <table id="dataTable" class="CSSTableGenerator"> <tbody> <tr> <td>< ...

Break apart the values of a Bootstrap multiselect into separate variables

Can you please assist me? I am trying to extract separate values from a multi-select field. var branch=$('#branch').value; //branch = 101,102,103; I need these values to be separated like this: id='101' or id='102'... My g ...

Guard your state with Vuex-persistedstate from the prying eyes of sessionStorage

As I develop an interactive quiz web application using Vue js and .NET Web API, I've integrated JSON Web Token authentication to store tokens in local storage. Additionally, I utilize vuex-persistedstate for maintaining state across routes. Storing da ...

Utilizing Laravel for Making Ajax Calls to Controller

I am a beginner in using Laravel and I am trying to create an API with Laravel using AJAX calls. However, when I make the AJAX call, the URL appears to show an invalid server path. Below is my code: My Route file : Route::get("a/b","AController@c"); My ...

Unable to Add Dependency to Subclassed Object

In my setup, there are three classes that interact with each other. I am utilizing inversify for handling dependency injection. However, I encountered an issue when I injected the class MessageBroker into the derived class Repository and found that the Mes ...

Node.js experiencing CORS problem causing failure

app.use(function (req, res, next) { // Allowing connection to a specific website res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8100'); // Allowing specific request headers res.setHeader('Access-Co ...

Working with Multiple Where Clauses in Laravel

I needed a list of foods that are in both the cart and favorites table. I attempted to achieve this by using a specific query. In the Conditional Clauses section, my goal was to check if a food item is present in either the favorites or carts table. Howe ...

Encountering issues when passing a string as query parameters

How can I successfully pass a string value along with navigation from one component to another using query parameters? Component1: stringData = "Hello"; this.router.navigate(['component2'], { queryParams: stringData }); Component2: ...

Enhancing the Bootstrap container using JavaScript

I am working with a Bootstrap container: <div class="container"> <div class="jumbotron"> <div class="row"> <div class="col-lg-8"> <form action="upl ...

What is the process for removing an added message using jQuery after it has been appended by clicking the same button?

https://i.stack.imgur.com/YsmKZ.pnghttps://i.stack.imgur.com/dW2lo.pngI have searched extensively through previously asked questions without success. My goal is to remove the previous appended message when the submit button is clicked again. This functiona ...

Expanding the scope value in Angular through ng-repeat iteration

Is it possible to increase the value in $scope by using values from an ng-repeat loop? Here is the code snippet I am working with: <div ng-repeat="field in selected.inhoud.fields"> <p>Field Name: {{field.title}}</p> <p>Size in ...

Loading 3D models in Three.js from the cache

Every time my page reloads, the loader loads objects from the URL instead of cache. Is there a way to check if the resource is in cache and load it directly? Appreciate your help! ...

What is the best way to implement the verifyToken middleware into my Express router modules?

I am facing an issue with my express app setup, here is a glimpse: // index.js const express = require('express'); const app = express(); const userRoutes = require('./routes/userRoutes'); app.use('/user', userRoutes); const ...

What is the method of locating the default export reference of a file in Visual Studio Code?

Is it possible to locate the reference file that is exported by default in Visual Studio Code? The key shortcut to find all references in VSCode is: alt + shift + f12. For instance, consider finding data.js. async function update(req, res) { res.render ...