Issues with Next and Previous Buttons code on Dynamic Page

I’m trying to get my next and previous buttons working on my dynamic item pages. Following this tutorial: Velo Tutorial: Creating Previous and Next Buttons for a Dynamic Item Page with Code | Help Center | Wix.com

I have successfully entered the code on the items page, but I have issues with the code on the index page.

You can see below that I have already changed the linkField definition to what my fieldNames are in the dynamic item page url’s. Is this correct? My item page url’s end with two fieldNames separated by a “/”.
(Ex. "http…/firstName/lastName).

Also, when I change the #myDataset to the fieldName of my dataset (or even if I change my dataset fieldName to #myDataset), an error pops up for the dynamicPageURLs on the last line (line 12). It’s as if something is different about my own dataset I’m using for the dynamic page that doesn’t let this code work with my dataset. You can see the error in the comments.

Please help.

import {local} from 'wix-storage';

const linkField = "firstName"+"lastName"; // replace this value

$w.onReady(function () {
  $w("#myDataset").onReady(() => {
    const numberOfItems = $w("#myDataset").getTotalCount();
  
    $w("#myDataset").getItems(0, numberOfItems)
      .then( (result) => { 
        const dynamicPageURLs = result.items.map(item => item[linkField]);
        local.setItem('dynamicPageURLs', dynamicPageURLs);
      } )
      .catch( (err) => {
        console.log(err.code, err.message);
      } );
  } );
} );

Argument of type ‘any[]’ is not assignable to parameter of type ‘string | number’. Type ‘any[]’ is not assignable to type ‘string’.

This is the error I get for the dynamicPageURLs in the line: local.setItem(‘dynamicPageURLs’, dynamicPageURLs );

As the error says only string or numbers can be saved into the storage. And the dynamicPageURLs is an array.

You can convert array into object:

let obj = Object.assign({}, dynamicPageURLs);

Then use stringiy it when saving to the storage variable:

local.setItem('dynamicPageURLs', JSON.stringify(obj));

The parse it back to and object when getting from the storage.

Thank you! My friend actually already helped me out. I had put the wrong value for the linkField input and then did some other things wrong with the settings of the buttons. All good now, I appreciate your response.