PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, June 30, 2022

[FIXED] Why would joining an array work, but not accessing individual elements?

 June 30, 2022     liquid, shopify     No comments   

Issue

I've just started working on customizing my Shopify template, but I've ran into a basic issue, where the docs didn't help.

<script>console.log("_{{ item.properties | join: ", " }}_");</script>
// prints "_foo1, foo2_"

<script>console.log("_{{ item.properties[0] }}_");</script>
// prints "__"

<script>console.log("_{{ item.properties }}_");</script>
// prints "_EscapedHashDrop_"

Thanks!


Solution

you are getting value in string in first console and try to fetch value as a array in second console so it's not possible

you have to convert your string value in array by using .split() function.

Try this code it will give result according to you.

var itemvalue = "_{{ item.properties | join: ", " }}_";
   // console.log(itemvalue); --->  print  "_foo1, foo2_"
    var myvalue = itemvalue.split(",");
    console.log(myvalue[0]);


Answered By - Dotsquares
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,207,188

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing