extracting multiple cookie values and assigning them to variables in Angular

Here is the code snippet I am working with:

var ietms = $cookies.get('items');

Although I can retrieve values, they appear in multiples like:

Testvalue1|Testvalue2|testvalue3

I would like to separate these three items into individual variables, for example:

var ietms = $cookies.get('items')[0];
var ietms2 = $cookies.get('items')[1];
var ietms3 = $cookies.get('items')[2];

The goal is to split the value based on the '|' delimiter that separates the values.

Answer №1

When dealing with a string as the returned data, one method is to use

var splitItems = items.split('|')
in order to generate an array containing each separate value. However, it's difficult to determine if this technique is relevant to your specific inquiry since the output type of testvalue1|..|.. remains ambiguous.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

HTML and JavaScript: Struggling to include multiple parameters in onclick event even after escaping quotes

I am struggling to correctly append an HTML div with multiple parameters in the onclick function. Despite using escaped quotes, the rendered HTML is not displaying as intended. Here is the original HTML code: $("#city-list").append("<div class='u ...

Error: Attempting to access a property of an undefined object using method chaining

I encountered an error of property undefined with the code below. I'm not sure what's causing it. I checked by doing a console.log(navList) in the render and it does have a value. Even after adding if(!navList) return null, I still get the same e ...

Populate an ng-repeat table again while maintaining its original sorting order

Incorporating a table filled with data fetched from a webservice using the ng-repeat directive, I have enabled sorting functionality for all columns. Additionally, at regular intervals, the application polls the webservice to retrieve updated data. This o ...

The content in Ionic is revealed only after the SideMenu has been clicked on

My Ionic App was functioning correctly, but now it is exhibiting some strange behavior. Initially, when I run the app, it does not display any data. However, after clicking on the side menu once or twice, the data loads and appears. The data for my app com ...

ways to assign the total of string array elements to the $scope variable

I've been working on binding the total sum of selected checkboxes within a table. I'm almost there, but something isn't quite right. The image above shows 2 checkboxes selected. https://i.sstatic.net/70af2.jpg The code snippet below showcas ...

Tips for navigating the HTML DOM without using window.scrollBy(x, y) (specifically for scrolling within an element)

Desiring to scroll down along with my selected document, I experimented with the following code. window.scrollTo(x, y); const body = document.getElementsByClassName("body")[0]; body.scrollTo(x, y); However, there are instances where it returns "undefined ...

The height of divs spontaneously changes after resizing without any instructions

I am developing a jQuery function to vertically center an element. The function is triggered on load and here is the code: JQuery var $window_height; function Centerize(content) { content.css('margin-top', (($window_height - content.height( ...

If $urlRouterProvider.otherwise is used, $stateProvider will not handle the routing

Previously, when "/" was set as "/main", the code was able to load both main and dashboard using $urlRouterProvider.otherwise("/main/dashboard"); However, after changing it to just "/", the dashboard does not load anymore. This change was made due to an i ...

Unable to integrate npm package into Nuxt.js, encountering issues with [vue-star-rating] plugin

Just starting with nuxt js and running into issues when trying to add npm packages. Below are my attempts. star-raing.js import Vue from 'vue' import StarsRatings from 'vue-star-rating' Vue.use(StarsRatings) nuxt.config.js plugi ...

Troubleshooting a scope problem with ng-include while maintaining the original template

I have a select box within my template that has the following structure: <form name="myForm" class="fixed-select"> <select name="repeatSelect" id="repeatSelect" ng-model="selectedItem"> <option ng-repeat="program in pro ...

Which is the better choice for me - webpack or create-react-app?

What's the best way to kickstart my react app - webpack or create-react-app? Are there any benefits to using webpack instead of create-react-app? ...

Getting the text from an HTML input field requires accessing the value property of the

My goal is to generate a pdf report using php. The user will enter their name in an input box, which will then be passed to the second php page that searches the mysql database. Issue: When the user inputs their name, attempting to retrieve the data (var ...

Can anyone please guide me on how to extract the IP address of a specific individual using Node.js?

There's an individual running some kind of exploit scanner on my server. I'm receiving strange requests like: IP ADDRESS: ::ffff:127.0.0.1 www-0 (out): POST /cgi-bin/php5?%2D%64+%61%6C%6C%6F%77%5F%75%72%6C%5F%69%6E%63%6C%75%64%65%3D%6F%6E+%2D%64 ...

Is there a way to integrate a PHP variable into JavaScript's getTime() function?

I'm attempting to compare two dates: one is the current date, and the other is a date stored in my database (retrieved through an SQL query). I was advised to use new Date(), but I'm unsure how to include a php variable in the script. Here is the ...

why is it that I am not achieving the expected results in certain areas of my work?

I am facing issues with getting an alert response from certain buttons in the code. The AC button, EQUALS button, and the button labeled "11" are not behaving as expected. I have tried troubleshooting but cannot identify the problem. Can someone please ass ...

next.js users may encounter a problem with react-table not rendering correctly

Encountering difficulties while attempting to integrate a basic table function into my upcoming application. Despite being a sample output, the function fails to load into the index for some unknown reason! // Layouts import Layout from "../components ...

Using Javascript to Retrieve Object-Related Information from an Associative Array

I have a list of students' names along with the grades they achieved for the semester. How can I modify my JavaScript code to display the first names of students who earned an "A" grade based on the array provided? This is my current progress, but I k ...

How to successfully submit an array using Vue.js

Having an issue with a form that allows users to enter multiple inputs of the same field as an array. However, encountering two errors when trying to submit the form. Error 1 : The value always returns as 'undefined', possibly due to incorrect a ...

Navigating to an AngularJS state through an email hyperlink

Trying to guide users from an email link to a specific state within my Angular app presents a challenge due to its single page nature, making direct URL redirection impossible. Past attempts involved utilizing URL parameters: The email includes this link ...

Issue with AngularJS: Copying and appending with $compile is not functioning properly

Below is the snippet of my angularjs Controller var $tr = angular.element("#parent" + obj.field_id).find("tbody"), $nlast = $tr.find("tr:last"), $clone = angular.copy($nlast); $clone.find(':text').val('' ...