How to seperate item in array using react

Shubham Sharma :

user.js

import React, { useState, useEffect } from 'react';
import Axios from 'axios';

const RecommendationDetail = () => {
  const [image, setImage] = useState([]);

  useEffect(() => {
    loadRekko();
}, []);


  const loadRekko = async () => {
    const res = await Axios.get(`http://localhost:3001/dashboard-rekko/${id}`,{
        headers:headers
    }); 


    console.log(res.data.response);
    var array = [];
    let a = (res.data.response.rekkoRecords.product_img)
    array.push(a)
    setImage(array)    ====>>> How can i make array like i want
    console.log(image)
    setRecommendation(res.data.response.rekkoRecords)
  }

 return (
    {image.map((it) => {
            return (
                <div key={it}>
                    <img src= {'http://localhost:3001/'+it} />
                </div>
            )
            
        })}
 )
}

Everything is working but I want to show multiple images. I am getting a response in "uploads\classpamplate.png,uploads\classpamplate1.jpg" this format and after pushing it in the array it becomes ["uploads\classpamplate.png,uploads\classpamplate1.jpg"] but what I want is ["uploads\classpamplate.png","uploads\classpamplate1.jpg"] both are separated so that I can show it using .map() function. Any help will be appreciated

r7r :

I am assuming a = "uploads\classpamplate.png,uploads\classpamplate1.jpg"

expected result = ["uploads\classpamplate.png","uploads\classpamplate1.jpg"]

Don't push a in the array, try below

setImage(a.split(','))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Seperate each item in an array

How to loop through array and push it into a seperate array based on some conditions using react?

How to create an array of objects in React Native from seperate components?

How to create seperate component just for routes using react router?

How to store indeces of the respective numbers in a list in seperate array using Python

How can I append an item to an array in a React component using hooks?

How to find item in array in React

How to make visits count seperate for each item

using pandas to count how often an item appears in a seperate dataframe based on a condition

Rendering an array of components with seperate states in React

How to Seperate Array with equals to and create single array

React scroll nav using useRef in seperate routes

How to retrieve property from an array of object and those in a seperate object using javascript?

How to store multiple values of HTML dropdownlist into array and seperate them by comma using PHP?

How do I seperate an array of IPC values

How can I seperate a maths formula into array

How to seperate nested array from Map ? - Java

How can I seperate an array into different 'mags'

How to seperate an array value and put into DataFrame in pandas

How to get array value in seperate combobox

How to remove item correctly from an array in react?

How to display each item in an array in React JS?

How to delete The array item in react js?

How to remove Item from an array with react and firebase

How to get index of the clicked images which is an item of array using React native

How to get index of the clicked images which is an item of array using React native

using react-dnd beautiful how do I insert new item into the array, or does it not work?

How to seperate a column element in a view using a delimiter?

How to seperate integer values using sscanf in c?