e1commerce.com
Ask a question
  • New questions
  • With the answers
  • Unanswered
  1. Home
  2. arrays - Instead of null, send a message for no value in Javascript

801 votes
1 answers

arrays - Instead of null, send a message for no value in Javascript

Solution:

Try out the below code this should fix your bug if not then let me know. I will try another method of rendering an empty statement.

const emptyStatement = () => {
  const empty_Statement = "You have no wishlist item.";
  const resetWishlist = empty_Statement;
  return setWishlist([empty_Statement]);

  document.getElementById("oasis-wishlist").innerHTML = emptyStatement();
};

Undefined asked
2022-12-30


93
votes

Answer

Solution:

Ok. so here you can add a condition while fetching Wishlist products. ifproductarr.length==0 then set the inner HTML of Wishlist to<h1> Wishlist empty </h1> else if there is data then print the data as per your choice. i can't actually provide the code because it will alter whole of your code. apply the above logic accordingly and that will fix your code.

fetch(url).then((res)=>
{
if(res.data.length)
    setwihslist([res.data])
else
    wishlist.innerHTML="emptywishlist";
}
Undefined answered
2022-12-30
Link to answer


Source

Didn't find the answer?

Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Similar questions

Find the answer in similar questions on our website.

182 arrays - Instead of null, send a message for no value in Javascript
483 node.js - Heroku: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory even after changing NODE OPTIONS
729 shopify - How to search for a value in a tag that is stored as "key:value"
994 liquid - How to no-index specific pages on shopify? Don't want to use "contains" example for shopify, can I just type "="? And what denotes as the handle?
409 node.js - How to create a REST request using the Shopify Node JS API for a Private App?
742 javascript - Is it possible to fix the positions of last three slides within the slick slider?
991 javascript - NextJs function call not accepting passed argument variable
33 javascript - How do I return the response from an asynchronous call?
736 javascript - Replacing the text by using jQuery script in shopify platform on the product page
269 Asynchronous rendering of Shopify Liquid Snippet in theme app extensions

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.







Latest questions:

292 Triggering Zapier on new Shopify order containing a specific product

617 javascript - Swiper js - How can i change the background color of the selected slide

771 Shopify Webhooks not redirect into Laravel Route

586 How to enable / disable my app that is being managed from theme customization section shopify

72 Shopify List Blog Tags



© 2021

E-mail: infot@e1commerce.com