cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
dileepkr
Level III

Appending element to a list value inside an associative array

Hi,

 

I am trying to add an element into an associative array where the value is a list and the element needs to be added into the list inside associative array.

Eg:

cary = ["high schools" => {"Cary", "Green Hope", "Panther Creek"}, "population" => 116244, "state" => "NC", "weather" => "sunny"];

 

In this,

1. How can I add a new entry to "high schools" list?

2. How do I convert the "weather" value to list? i.e. "weather" => {"sunny", "humid"}

 

Any help regarding this is much appreciated.

 

Thanks,
Dileep

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Appending element to a list value inside an associative array

There's likely a simpler way but the below seems to work.

cary = ["high schools" => {"Cary", "Green Hope", "Panther Creek"}, "population" => 116244,
"state" => "NC",
"weather" => "sunny"];

// 1.
cary << Insert("high schools", Insert(cary["high schools"], "another school"));
// 2.
cary << Insert("weather", Eval List(Insert(List(cary["weather"]), "humid")));

Show(cary);
/*:

cary = ["high schools" => {"Cary", "Green Hope", "Panther Creek", "another school"}, "population" => 116244, "state" => "NC", "weather" => {"sunny", "humid"}];

 

View solution in original post

2 REPLIES 2
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Appending element to a list value inside an associative array

There's likely a simpler way but the below seems to work.

cary = ["high schools" => {"Cary", "Green Hope", "Panther Creek"}, "population" => 116244,
"state" => "NC",
"weather" => "sunny"];

// 1.
cary << Insert("high schools", Insert(cary["high schools"], "another school"));
// 2.
cary << Insert("weather", Eval List(Insert(List(cary["weather"]), "humid")));

Show(cary);
/*:

cary = ["high schools" => {"Cary", "Green Hope", "Panther Creek", "another school"}, "population" => 116244, "state" => "NC", "weather" => {"sunny", "humid"}];

 

Re: Appending element to a list value inside an associative array

There is usually more than one way with JSL. Here is my way:

 

cary = ["high schools" => {"Cary", "Green Hope", "Panther Creek"}, "population" => 116244, "state" => "NC", "weather" => "sunny"];

Insert Into( cary["high schools"], "Black Bear" );

cary["weather"] = { "sunny", "humid" };

I am sure that the specific details will determine which way is best for you in this case.

Recommended Articles