Show the strings amongst each other

Using my BackEnd API, a string is returned to me. For example, the response is :

test.sh has been executed by Java,test.sh has been executed by Java,test.sh has been executed by Java

I am looking to split this string at "," and display each item separately. The desired output should be:

1. test.sh has been executed by Java
2. test.sh has been executed by Java
3. test.sh has been executed by Java

Currently, the string appears as follows:

1. test.sh has been executed by Java,test.sh has been executed by Java,test.sh has been executed by Java

Here is the frontend code I have implemented:

<template>
<v-form>
    <v-container>
      <v-card
          class="mt-15 pa-4  mx-auto"
          max-width="700"
          color="#BDBDBD"
          text = "red darken-1"
      >
        <ol>
          <li class="white--text" v-for="item in output" :key="item">{{item}}</li>
        </ol>
      </v-card>
    </v-container>
    </v-form>
    </template>
    <script>
     export default {
     data: () => ({
items: [],
search: null,
key: '',
output: [],
}),
 methods: {
  async displayTerminalLog() {
    let apiUrl = 'http://localhost:8091/api/v1/output/'
    let response = await this.axios.get(apiUrl);
    console.log(response.data.toString())
    for (var text in response.data.toString().split(",")){
      this.output.push(response.data[text].slice(0, 
      response.data.toString().length-1))}
  }
}
    }
   </script>

Answer №1

When using the For…in loop, it will iterate over the keys of an object. If you are working with an Array, consider using for…of loop instead. Take a look at this code snippet...

for (var item of response.data.toString().split(",")){
// …

Answer №2

const dataArr = response.data.toString().split(", ");
dataArr.forEach((element, position) => {
    console.log((position + 1) + '. ' + element)
})

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

React component with adjustable zoom settings

I'm searching for a way to implement a zoomable element in React. My goal is to display a larger image and additional information when clicking on any picture from a list of pictures. Upon clicking again, I'd like the image to zoom out. Can anyon ...

React 16 Component Size Attribute (size="test") is being eliminated

Is anyone else encountering a similar issue where the size attribute of a React component is getting removed? For example, `ReactDOM.render( <h1 size="hello">Hello, world!</h1>, document.getElementById("root") );` You ...

Press the button within the nested component to send information to the parent component through another intermediate child component

Can data be passed by clicking on a button in a nested child component, then passed to another child component one level above, and finally to the parent component? This is how my components are nested: Parent ----Child ---------Child 2 (with a button th ...

React Syntax Error: Regular Expression Unfinished

Within my React project, I am assigning the news variable to the setNews state. To utilize the map method in my JSX, I am passing news as a destructured prop. However, when attempting to nest specific data fields from the API that I am using, an error aris ...

How can I access attribute type information in a Node.js Sequelize model?

I have successfully implemented a model in NodeJS using Postgres and sequelize. Let's say the model is Person and it includes fields for name and age. Now, I am looking to dynamically examine the model class to retrieve details about its attributes, s ...

Retrieve information from Angular service's HTTP response

Calling all Angular/Javascript aficionados! I need some help with a service that makes API calls to fetch data: app.service("GetDivision", ["$http", function($http){ this.division = function(divisionNumber){ $http.post("/api/division", {division:di ...

Is utilizing React's useEffect hook along with creating your own asynchronous function to fetch data the best approach

After attempting to craft a function for retrieving data from the server, I successfully made it work. However, I am uncertain if this is the correct approach. I utilized a function component to fetch data, incorporating useState, useEffect, and Async/Awa ...

What is the best method for accessing data values from HTML within a JavaScript function?

Greetings, I am relatively new to using jquery and ajax. Here is a snippet of my code: .html <li class="list-group-item"> <h2>Vocabulary</h2> <h4> <span class="label label-success">Like Name</span& ...

Adjust the size of a collapsed element in a bootstrap accordion panel

I am working with a classic bootstrap accordion in my code. I want to adjust the width of the expanded ul/li elements when a h5 element is clicked (decrease width). Currently, the width expands fully when the h5 element is clicked. Can anyone provide ass ...

Utilizing browserify, uglify, and exorcist in npm scripts for efficient bundling and min

Can anyone assist me with executing a series of commands in npm scripts during the creation of a js application? Currently, I am using the following command: "scripts": { "build-js": "browserify src/app/main.js --debug | exorcist dist/app.js.map > ...

Swapping out the identifier 'datepicker' with the model attribute 'due_date' when integrating a datepicker within a Rails form

In my form, I have the following code snippet: <div class="row"> <%= t.label :name, 'Due Date' %><br> <%= t.text_field :due_date, id: 'datepicker' %> </div> The id attribute is necessary for ...

Is there a way to trigger a dropdown menu when my 'li' element is clicked on the Services option?

I need help creating a customized navigation bar. I want the Services and Plans list items to display drop-down menus when clicked. However, instead of working as expected, I'm encountering an error message that says: 'cannot read property contai ...

Displaying entered values in a text box after typing or inputting data

I am trying to display the value entered in a text box in an alert box without using any forms or buttons. However, my current code is not working as expected and it gives a null value on loading the file. HTML <tr> <td><br>Address ...

Using VueJS's vue-router to match multiple paths effortlessly

I need assistance with vue-router as I am trying to find a way to match two completely different paths. Can someone suggest if there is an array notation that I can utilize for this purpose? ...

Leveraging the ng-hide property of one controller to adjust the ng-style attribute of another controller through a centralized global controller

Seeking assistance with accessing the boolean value of ng-hide from one controller in order to alter CSS properties of another controller utilizing a global controller. Here is the jsfiddle link: https://jsfiddle.net/dqmtLxnt/ HTML <div ng-controller= ...

Determining Marker Location Post Drag in Laravel-VUE Component

I have integrated vue-google-maps into my project and it is working well so far. My goal is to have a marker appear when a user searches and selects their area, and then they can drag the marker to the desired position. I have successfully made the marker ...

Using JavaScript, transform an integer value into a time format

I successfully converted a feed's published date "pubDate" to an integer using JavaScript. Below is the code snippet I implemented for this task. function timetoint(date){ var date = new Date(date); return Math.round(date.getTime()/1000); } ...

Accessing the content of a jQuery editor in PHP

I have been utilizing a jquery plugin for developing a wysiwyg text editor. In my PHP code, I have created a textarea like this: <textarea name="body" id="body"><?php echo $body?></textarea> Also, added the following ...

Truncating decimal points in JavaScript

In this scenario, if the number after the decimal point is 0, then the zero should be removed. Otherwise, the number should be displayed as it is. Here are some examples of what I am aiming for in vue: 100.023 => 100.023 1230.0 => 1230 ...

Can a form be submitted to two different pages based on the button name?

I have a form that directs to another page and performs various database operations. <form id="form1" method="post" action="goes_to_page1.php" onsubmit="return checkformvalidation();"> <input type="text" id="field1" name="field1" onblur="checkva ...