0
deleteImages = (images, index, onComplete) => {
    const deleteAgain = (images, index, onCompleted) => 
    this.deleteImages(images, index, onCompleted);

    let splited_link = images[index].split("/")
    let name = splited_link[splited_link.length - 1].split("?")[0].replace("banners%2F", "");

    console.log(name)
  }

Hello guys.

Guys please help i am junior. Error in my this code.

Uncaught TypeError: images[index].split is not a function
    at HomeFragment.deleteImages (HomeFragment.js:375:1)
    at delete (HomeFragment.js:480:1)

split is not a function split is not a function

2

1 Answer 1

1

The method split is only available for strings. So this error will occur every time you try to call it in a variable that is not a string.

In your case, you probably are trying to access an index that is not in the array images, or inserted something that is not of type string in images.

Try to log what is in the variable right before the error:

  deleteImages = (images, index, onComplete) => {
    const deleteAgain = (images, index, onCompleted) => 
    this.deleteImages(images, index, onCompleted);

    console.log(images[index], index, images.length); // this will do
    let splited_link = images[index].split("/")
    let name = splited_link[splited_link.length - 1].split("?")[0].replace("banners%2F", "");

  }

Examples of what can be happening:

const images = ['a', 'b', 1]
images[1].split() // Everything works fine
images[2].split() // Error because index 2 is a integer
images[3].split() // Error because index 3 do not exist in images
Sign up to request clarification or add additional context in comments.

6 Comments

try to add the console.log before the splited_link and check what is the last value logged
this code return console.log(images[index]);
{banner: 'firebasestorage.googleapis.com/v0/b/marly-…=media&token=51b74afe-0025-426d-b504-df93023353ba'} banner: "firebasestorage.googleapis.com/v0/b/marly-b3b4e.appspot.com/o/…" [[Prototype]]: Object
can you please share your complete response of images?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.