Verify if the items in the array are based on ASCII codes

I'm looking to extract ASCII codes from elements within an array. Here's a sample array:

var elem = ["Joe", "M"+String.fromCharCode(13)+"ry", "Element_03", "Element_04"];

I tried using a for loop to scan through the array and check for ASCII codes in each element, but so far I haven't been successful.

Answer №1

let table={};
characters.forEach(function(item){
  for(let index=0;index<item.length;index++){
    table[item.charCodeAt(index)]=true;
  }
});
console.log(Object.keys(table));

Iterate through the characters in the provided array and add each character's code to a hash table.

Answer №2

It seems like you're looking to identify non-alphanumeric characters within each element of an array. For instance, the character with CharCode 13 represents a carriage return. Depending on your definition of "special," this approach might be helpful.

const elements = ["Joe", "M"+String.fromCharCode(13)+"ry", "Element_03", "Element_04"];

const foundCodes = {};

elements.join('').split('').forEach(character => {
  const code = character.charCodeAt(0);
  if ( code < 32 || code > 126 ) {
    foundCodes[code] = true;
  }
});

console.log(Object.keys(foundCodes));

I'm referring to this ASCII table for assistance, but you can see the results directly in my code.

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

Certain URLs do not receive requests when using jQuery.ajax(), while others are successful

Our Rails application features inline editing, allowing users to submit changes back to the server via PUT requests. The URL for the PUT request varies based on the object being edited and the page the user is on. The same JavaScript code supports this fea ...

Designing an uncomplicated password authentication system without embedding the password itself [Using PHP, Javascript, and MySQL]

I'm in the process of setting up a basic login prompt for my local website. I initially experimented with Javascript, but I'm looking for a way to avoid hardcoding the password. Users receive their passwords via email, so there's no need for ...

What steps should be taken in order to ensure the effectiveness of this keyword search

Currently, I am attempting to implement a keyword search feature for my meteor web app. Although the functionality is there, it's running quite slow. The way it works now is that when a user creates an article, they assign keywords to it. The keyS fun ...

Effortlessly create a seamless transition in background color opacity once the base image has finished

I've set up a div with a sleek black background. Upon page load, I trigger an API request for an image, which is then displayed in a secondary div positioned behind the main one. After this, I aim to smoothly transition the overlaying div's opaci ...

What is the best way to transfer data from Material UI to Formik?

I'm facing an issue when trying to integrate a Material UI 'Select' component into my Formik form. It seems like I am unable to pass the selected values from the Material UI component to Formik's initialValues. const [selectedHours, se ...

Altering the value of a form upon submission

Struggling with Javascript to update an input value before submitting and storing it in a MySQL table, I encounter the issue of getting a blank row in the database. The code snippet causing this problem looks like this: document.getElementsByName('w ...

Troublesome issue with custom select feature in foundation when used within a button

I'm currently incorporating Zurb Foundation 4 into my website and using the "custom forms" feature for special styling on form elements. The issue I'm facing is that HTML select elements aren't functioning properly when placed inside a butto ...

After reloading the page, Nuxt dynamic routes are displaying a 404 error

Hey there! I'm currently diving into a project that involves using nuxt js, and it's all new to me. I've set it up in spa mode without any modifications in the nuxt config file, just sticking with the default settings. Here's how I&apos ...

Exploring the process of implementing smooth transitions when toggling between light and dark modes using JavaScript

var container = document.querySelector(".container") var light2 = document.getElementById("light"); var dark2 = document.getElementById("dark"); light2.addEventListener('click', lightMode); function lightMode(){ contai ...

After the initial iteration, the .length function ceases to function properly when

A validation method is set up to check the length of a user input field. It functions properly on the initial try, but does not update if I go back and modify the field. $("#user").blur(function () { if ($("#user").val().length < 3) { $("#userval ...

Ways to alert user prior to exiting page without initiating a redirect

I have a feature on my website where users can create and edit posts. I want to notify them before leaving the page in these sections. Here's how I can accomplish that: //Add warning only if user is on a New or Edit page if(window.location.href.index ...

What is the best way to differentiate between a JSON object and a Waterline model instance?

Note: I have posted an issue regarding this on the Waterline repo, but unfortunately, I have not received a simpler solution than my current workaround. Within my User model, along with default attributes such as createdDate and modifiedDate, I also have ...

`A Java dilemma: Struggling to determine the limits of integer frequency within a sorted array`

I am currently working on a function that determines the boundaries of a key in a sorted array. This function takes in an array and a key as parameters, and then calculates the lower and upper bounds based on the array's content and the given key (e.g ...

Is it possible for AngularJS to share a service among multiple ng-apps?

I've been working on developing a web app that involves multiple Angular ng-apps, and I want to use the same service code for at least two of them (even though they don't share data but perform similar functions). How can I prevent code duplicati ...

Having trouble using jQuery's .off() method to remove an event handler?

I'm facing an issue with my jQuery code where the .off('click') method doesn't seem to be working. I've tried removing the event binding from '.reveal-menu', but it's not working as expected. The initial animation wo ...

Vue's computed property utilizing typed variables

I am trying to create a computed array of type Todo[], but I keep encountering this specific error: No overload matches this call. Overload 1 of 2, '(getter: ComputedGetter<Todo[]>, debugOptions?: DebuggerOptions | undefined): ComputedRef<T ...

A new reference is created when Angular.copy is used

Whenever I attempt to duplicate a new object into an old object using angular.copy, the reference changes. If I try using = or JSON.parse(JSON.stringify(newObj)), the view does not reflect the new value. Is there a solution to this issue? Here is a code ...

Reconfigure a portion of a string using Vue's dynamic replacement feature

Currently tackling a problem. In my possession is a string that essentially consists of HTML code: let htmlTitle = "<a href="/news/sky-sport-hd-in-italia-dal-18-novembr">Sky Sport HD in italia dal 18 novembre</a> | <a href="/news/ecco-il-g ...

What is the error message "Subscript needs array or pointer type"? Are functions involved as well?

As a novice in C++, I am struggling with creating functions to handle different tasks. Although I feel confident in performing each task within the main function, I am unsure how to divide them into separate functions. For instance, I am unsure on how to s ...

Will other functions in the file run if only a single function is imported?

The file bmiCalculator.ts contains the following code: import { isNotNumber } from './utils'; export default function calculateBmi(height: number, weight: number) { const bmi = weight / Math.pow(height / 100, 2); if (bmi < 18.5) { re ...