JE::Ob...::Array(3pm)

πŸ“¦
version 0.066 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ‘‘ JE::Ob...::Array(3pm) β€” bestie, it's the JavaScript Array era

okay so real talk, this page lives in the User Contributed Perl Documentation collection, and it's your girl JE::Ob...::Array(3pm) β€” yes the title got cut off in the header, it's giving mysterious πŸ’…, but the actual module is JE::Object::Array. come sit with me.


✨ NAME ✨

JE::Object β€” it's the JavaScript Array object class, no cap πŸ“


πŸ¦‹ SYNOPSIS πŸ¦‹

use JE;
use JE::Object::Array;

$j = new JE;

$js_array = new JE::Object::Array $j, 1, 2, 3;

$perl_arrayref = $js_array->value; # returns [1, 2, 3]

$js_array->[1]; # same as $js_array->value->[1]

"$js_array"; # returns "1,2,3"

like. look at her. iconic behavior from start to finish 😭✨


πŸ’– DESCRIPTION πŸ’–

This module implements JavaScript Array objects. that's the whole vibe. arrays, but JavaScript-flavored, living rent free in your Perl process 🫢

The @{} (array ref) operator is overloaded and returns a tied array that you can use to modify the array object itself. the way that it's tied?? obsessed. but heads up bestie:

The limitations and caveats mentioned in "JE::Object/"USING AN OBJECT AS A HASH"" apply here, too. fr fr, go read that section, it's not optional πŸ’€

🌸 METHODS 🌸

See JE::Types for descriptions of most of the methods β€” she's the big sister doc, she covers the basics. Only what is specific to JE::Object::Array is explained here. periodt.

  • $a = JE::Object::Array->new($global_obj, \@elements)
  • $a = JE::Object::Array->new($global_obj, $length)
  • $a = JE::Object::Array->new($global_obj, @elements)

This creates a new Array object. and the way it decides how depends on what you hand her:

  • If the second argument is an unblessed array ref, the elements of that array become the elements of the new array object. literally just slide the array ref in and she copies the vibes 🌈
  • If there are two arguments and the second is a JE::Number, a new array is created with that number as the length. so like, an empty array that knows how long it's supposed to be. main character energy πŸ‘‘
  • Otherwise, all arguments starting from the second one become elements of the new array object. so new JE::Object::Array $j, 1, 2, 3 just... becomes [1, 2, 3]. ate. πŸ’…
  • $a->value

This returns a reference to an array. but β€” and this is the important part, don't skip it 😭 β€” this is a copy of the Array object's internal array. if you want an array through which you can actually modify the object, use @$a. ngl that distinction is the whole game. don't come crying to me when your edits don't stick because you were poking at a copy πŸ™ˆ


πŸŽ€ SEE ALSO πŸŽ€

  • JE
  • JE::Types
  • JE::Object

the whole friend group. go say hi 🫢


lowkey a warning but make it cute: that @{} tied-array thing comes with the exact same limitations and caveats as the hash section over in JE::Object. no surprises, just read it before you get weird with it πŸ’œ

and that's the page, bestie!! πŸ’– this was perl v5.36.0, dated 2023-08-25, and it's the JE::Ob...::Array(3pm) page β€” slay, bye, go build an array πŸ¦‹βœ¨πŸ‘‘

πŸ“¦ where this page comes from